我正在使用 Material UI for React,我将 Material-UI 更新到最新版本,它给了我以下错误
../node_modules/material-ui/styles/withStyles.js
Module not found: Can't resolve '@babel/runtime/core-js/map' in
'C:\Users\User\Documents\code\react\node_modules\material-ui\styles'
我也降级到了先前版本的 Material-UI,也尝试安装正确版本的 babel,但仍然遇到同样的问题。
这是我的 package.json
"dependencies": {
"@babel/runtime": "^7.4.0",
"@material-ui/core": "^4.1.3",
"@material-ui/icons": "^3.0.2",
"@material-ui/lab": "^3.0.0-alpha.30",
"axios": "^0.18.1",
"bootstrap": "^4.3.1",
"material-auto-rotating-carousel": "^3.0.1",
"material-auto-rotating-carousel-refurb": "^1.0.1",
"react": "^16.8.6",
"react-animated-slider": "^1.1.4",
"react-bootstrap": "^0.32.4",
"react-dom": "^16.8.6",
"react-motion": "^0.5.2",
"react-responsive-carousel": "^3.1.49",
"react-router": "^3.2.3",
"react-scripts": "2.1.2",
"react-slick": "^0.23.2",
"react-swipeable-views": "^0.13.3",
"react-tap-event-plugin": "^1.0.0",
"slick-carousel": "^1.8.1"
}
最佳答案
我通过在 package.json
中添加解决方案解决了这个问题,但只有当您使用 yarn
而不是 npm
时它才会起作用>.
我的修复(如果您使用 yarn )
// in your package.json
...
"resolutions": {
"material-ui/@babel/runtime": "7.0.0-beta.42"
}
...
为什么它有效?因为 @babel/runtime": "7.0.0-beta.42
仍然需要 core-js
作为依赖项,具体来说它需要 core-js ^2.5.3
替代修复
如果您不使用 yarn
而是使用 npm
,您可以添加 @babel/runtime": "7.0.0-beta.42
作为 devDependency,它也应该可以正常工作。
我留下了yarn resolutions
的链接,因为您可能会感兴趣。
关于javascript - 如何解决模块未找到: Can't resolve '@babel/runtime/core-js/map' in Material-UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56845169/