执行 npm install 时,使用 React-scripts 版本创建 React App 错误

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

对于我的 Create React 应用程序,我在执行 npm install 时收到以下错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react-scripts
npm ERR!   react-scripts@"~5.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-scripts@"^4.0.0" from @craco/[email protected]
npm ERR! node_modules/@craco/craco
npm ERR!   dev @craco/craco@"~6.4.3" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

我的package.json如下

"dependencies": {
    "@fontsource/open-sans": "^4.5.13",
    "@fontsource/pt-mono": "^4.5.11",
    "@material-ui/core": "4.10.2",
    "@salt-ds/core": "1.8.1",
    "@salt-ds/data-grid": "^1.0.3",
    "ag-grid-community": "^25.0.0",
    "ag-grid-react": "^25.0.0",
    "@salt-ds/ag-grid-theme": "^1.3.3",
    "@salt-ds/lab": "^1.0.0-alpha.16",
    "@salt-ds/icons": "1.7.0",
    "@salt-ds/theme": "1.8.0",
    "axios": "^0.26.1",
    "history": "^5.3.0",
    "moment": "^2.29.4",
    "react": "^16.9.0",
    "react-app-polyfill": "^3.0.0",
    "react-cookie": "4.0.3",
    "react-dom": "^16.9.0",
    "react-hook-form": "^7.47.0",
    "react-hot-loader": "4.13.0",
    "react-refresh": "^0.11.0",
    "react-router-dom": "5.2.0",
    "react-scripts": "~5.0.1",
    "web-vitals": "^0.2.4"
  },
  "devDependencies": {
    "@craco/craco": "~6.4.3",
    "craco-module-federation": "1.1.0",
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.16.7",
    "@babel/plugin-transform-flow-strip-types": "^7.16.7",
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-flow": "^7.16.7",
    "@babel/preset-react": "^7.16.7",
    "@material-ui/types": "5.1.0",
    "@testing-library/dom": "8.1.0",
    "@testing-library/jest-dom": "5.14.1",
    "@testing-library/react": "11.2.7",
    "@testing-library/user-event": "14",
    "babel-loader": "^8.2.4",
    "babel-preset-es2015": "6.24.1",
    "cross-env": "7.0.3",
    "css-loader": "^6.7.1",
    "eslint": "8.12.0",
    "eslint-plugin-jest-dom": "4.0.1",
    "eslint-plugin-react": "7.29.4",
    "eslint-plugin-testing-library": "^5.3.1",
    "file-loader": "6.2.0",
    "jest": "27.5.1",
    "jest-sonar-reporter": "2.0.0",
    "msw": "^0.39.2",
    "path": "0.12.7",
    "prop-types": "^15.7.2",
    "resolve-url-loader": "^5.0.0",
    "style-loader": "^3.3.1",
    "typescript": "^4.6.3",
    "vite": "~4.3.8",
    "whatwg-fetch": "^3.6.2"
  },

不确定react-scripts和craco版本之间是否存在冲突。请推荐。

reactjs npm react-scripts craco
1个回答
-1
投票

尝试卸载 craco 并使用

--legacy-peer-deps
标志重新安装它。

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