前提
如何安装react:
https://medium.freecodecamp.org/part-1-react-app-from-scratch-using-webpack-4-562b1d231e75
新的babal的namespace在之前有个@(babel 8.x以上)
The recent Babel upgrade to version 7 changed the namings of the node packages.
For instance, now you have to install npm install --save-dev @babel/core @babel/preset-env
and npm install --save-dev @babel/preset-react
to get it working with React.
Then you can use these in your .babelrc file:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
Or as alternative, when not having a .babelrc, in your package.json:
...
"keywords": [],
"author": "",
"license": "ISC",
"babel": {
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
},
"devDependencies": {
...
If you want to get more into it, you can checkout this recent Webpack + Babel + React setup.
参考资料:
https://stackoverflow.com/questions/52067944/cannot-find-module-babel-core