【发布时间】:2022-06-13 14:00:09
【问题描述】:
将 "react-scripts": "4.0.3" 更新为 "react-scripts": "5.0.1", 后出现错误,让我知道为什么我收到此错误或如何解决此问题...
./node_modules/mime-types/index.js 15:14-37 中的错误
找不到模块:错误:无法解析“C:\work\sams-frontend-su\node_modules\mime-types”中的“路径”
重大变化:webpack
如果你想包含一个 polyfill,你需要: - 添加一个后备 'resolve.fallback: { "path": require.resolve("path-browserify") }' - 安装“路径浏览器” 如果您不想包含 polyfill,则可以使用这样的空模块: resolve.fallback: { "path": false }
另外,我在父路径中创建了一个 webpack.config.js 文件
module.exports = {
resolve: {
fallback: { "path": require.resolve("path-browserify") },
},
};
包.json
{
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/cli": "^7.17.10",
"@babel/core": "^7.18.0",
"@babel/preset-env": "^7.18.0",
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@mui/icons-material": "^5.8.0",
"@mui/lab": "^5.0.0-alpha.82",
"@mui/material": "^5.8.0",
"@mui/styles": "^5.8.0",
"antd": "^4.20.6",
"axios": "^0.27.2",
"formik": "^2.2.9",
"mime-types": "^2.1.35",
"moment": "^2.29.3",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-csv": "^2.2.2",
"react-draggable": "^4.4.5",
"react-scripts": "^5.0.1",
"react-table": "^7.8.0",
"react-window": "^1.8.7",
"spelling": "^2.0.2",
"yup": "^0.32.11"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0",
"react-dom": "^16.8.0 || ^17.0.0"
}
}
【问题讨论】:
-
SO answer 或 Github issue 是否能解决您的问题?
-
我检查了它,但他们提到在 node_modules 下添加该后备代码,但如果有人删除节点模块并再次安装,那么每次开发人员需要执行相同的过程时,这将不是一个永久的解决方案跨度>
-
这不是一个实用的解决方案,所以如果我们可以在父文件中添加 webpack.config.js 文件并在其下添加后备代码,如果我们可以做这样的事情会更好的解决方案跨度>
-
或者当我部署它时,服务器将 node_module 安装在存储桶中,然后在本地更新 node_module 下的 webpack.config.js,这将不起作用
-
您是否使用 Create React App(CRA) 引导您的应用程序?您的“package.json”文件似乎不正确。
标签: javascript reactjs npm