Redux Toolkit 不适用于react.tsx 版本

问题描述 投票:0回答:1

我已经尝试解决这个错误两天了,但仍然无法做到。谁能告诉我错误是什么以及如何解决它?

./node_modules/@reduxjs/toolkit/dist/redux-toolkit.legacy-esm.js 331:12
Module parse failed: Unexpected token (331:12)
File was processed with these loaders:
 * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|     return false;
|   }
>   if (cache?.has(value)) return false;
|   const entries = getEntries != null ? getEntries(value) : Object.entries(value);
|   const hasIgnoredPaths = ignoredPaths.length > 0;

以下是我的package.json文件,以防与redux工具包出现任何兼容性错误

    "@babel/plugin-proposal-class-properties": "^7.18.6",
    "@babel/preset-typescript": "^7.18.6",
    "@emotion/memoize": "^0.7.5",
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@fontsource/luckiest-guy": "^5.0.15",
    "@mui/material": "^5.11.7",
    "@react-pdf/font": "2.2.0",
    "@react-pdf/pdfkit": "^3.0.1",
    "@react-pdf/renderer": "3.0.2",
    "@reduxjs/toolkit": "^2.0.1",
    "@rtk-query/graphql-request-base-query": "https://pkg.csb.dev/reduxjs/redux-toolkit/commit/27edeffb/@rtk-query/graphql-request-base-query",
    "@stripe/react-stripe-js": "^1.7.0",
    "@stripe/stripe-js": "^1.22.0",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^12.1.5",
    "@testing-library/user-event": "^12.1.10",
    "@types/chart.js": "^2.9.37",
    "@types/jest": "^26.0.15",
    "@types/lodash": "^4.14.178",
    "@types/node": "17.0.8",
    "@types/react-dom": "^18.0.10",
    "@types/react-html-email": "^3.0.1",
    "@types/react-pdf": "^6.2.0",
    "@types/react-redux": "^7.1.24",
    "@types/testing-library__jest-dom": "^5.14.5",
    "@types/uuid": "^8.3.4",
    "@types/validator": "^13.7.10",
    "@u-wave/react-vimeo": "^0.9.10",
    "apexcharts": "^3.35.4",
    "axios": "^0.26.1",
    "body-parser": "^1.19.2",
    "bootstrap": "^5.1.3",
    "chart.js": "^2.7.3",
    "core-js": "^3.23.5",
    "cors": "^2.8.5",
    "dotenv": "^16.0.0",
    "draft-js": "^0.11.7",
    "draftjs-to-html": "^0.9.1",
    "fast-sass-loader": "^2.0.0",
    "firebase": "^9.6.10",
    "firebase-admin": "^10.0.2",
    "firebase-functions": "^3.19.0",
    "firebase-tools": "^10.0.1",
    "flux": "^3.1.3",
    "fontkit": "^2.0.2",
    "html-react-parser": "^2.0.0",
    "i18n": "^0.15.1",
    "include-media": "^1.4.10",
    "json-stable-stringify": "^1.1.0",
    "lodash": "^4.17.21",
    "moment": "^2.29.1",
    "my-ui-lib": "^1.2.2",
    "node": "^17.7.1",
    "pdfkit": "^0.13.0",
    "prettier": "^2.6.2",
    "react": "18",
    "react-admin": "^4.1.0",
    "react-apexcharts": "^1.4.0",
    "react-dom": "18",
    "react-ga4": "^1.4.1",
    "react-helmet": "^6.1.0",
    "react-modern-calendar-datepicker": "^3.1.6",
    "react-pdf": "^7.5.1",
    "react-quill": "^2.0.0",
    "react-redux": "^9.0.4",
    "react-responsive-carousel": "^3.2.22",
    "react-router-hash-link": "^2.4.3",
    "react-scripts": "4.0.3",
    "reactstrap": "^9.0.3",
    "resolve-url-loader": "^5.0.0",
    "shards-react": "^1.0.3",
    "source-map-explorer": "^2.5.2",
    "styled-components": "^5.3.3",
    "tar": "^6.1.11",
    "typescript": "^4.1.2",
    "uuid": "^8.3.2",
    "validator": "^13.7.0",
    "web-vitals": "^1.0.1"
  },
  "resolutions": {
    "@react-pdf/font": "2.2.0",
    "@react-pdf/pdfkit": "2.1.0",
    "pdfjs-dist": "2.16.105"
  },
  "devDependencies": {
    "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
    "@jest/globals": "^29.3.1",
    "@types/jquery": "^3.5.13",
    "@types/nodemailer": "^6.4.4",
    "@types/react": "^18.0.27",
    "@types/react-router-hash-link": "^2.4.4",
    "eslint-plugin-jest-dom": "^4.0.3",
    "express": "^4.17.3",
    "nodemon": "^2.0.15",
    "sass": "^1.49.9",
    "ts-jest": "^29.0.3",
    "webpack-bundle-analyzer": "^4.10.1"
  }

我将

react-scripts
更新到最新版本。也尝试更新其他但出现不兼容错误。 Redux-Toolkit 也是最新版本。

reactjs node.js typescript babeljs node-modules
1个回答
0
投票

删除node_modules和package-lock.json并将@types/react更改为

"@types/react": "18.2.46"

然后运行

npm i

再次

© www.soinside.com 2019 - 2024. All rights reserved.