如何解决未找到的模块:无法在Material-UI中解析'@ babel / runtime / core-js / map'

时间:2019-07-02 04:05:19

标签: javascript reactjs material-ui babeljs

我正在使用Material UI for React,我将Material-UI更新到最新版本,并且出现以下错误

  

../ node_modules / material-ui / styles / withStyles.js

     

找不到模块:无法在

中解析'@ babel / runtime / core-js / map'      

'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"
  }

1 个答案:

答案 0 :(得分:1)

我通过在我的package.json中添加一个分辨率来解决此问题,但是只有在您使用yarn而不是npm时,它才有效。

我的解决方法(如果使用毛线)

// 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的链接,因为它可能对您很有趣。