babel/core 6.x升级到7.x要碰到的一些坑
刚学习react.js没多久,碰到各种坑。就比如这个问题,弄了我3个小时,终于解决了。其实就是一个小问题。
报错信息:
Error: Cannot find module '@babel/core' babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'. at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) ....
当你装好了babel/core 6.x的话,那就先把babel-core 6.x的版本删了,安装@babel/core就可以了。我是利用cmd来删除的,在vs中会遇到权限问题,删不了。
npm un babel-core -D
cnpm i @babel/core -D
在把那些以前的老包都删了,要重新装一些新包:
"devDependencies": { "@babel/core": "^7.4.5", "@babel/plugin-proposal-object-rest-spread": "^7.4.4", "@babel/plugin-transform-runtime": "^7.4.4", "@babel/preset-env": "^7.4.5", "@babel/preset-react": "^7.0.0", "babel-loader": "^8.0.6", "babel-preset-mobx": "^2.0.0" }
之后在修改babelrc:
{ "presets":["@babel/preset-env", "@babel/preset-react", "mobx"], "plugins": ["@babel/plugin-proposal-object-rest-spread", "@babel/plugin-transform-runtime"] }