webpack 搭建react应用-babel不兼容

大前端使用工具 npm webpack react
本次升级脚手架搭建最新的框架
搭建框架时,遇到了babel 使用不兼容问题。
先使用了 babel/preset-react 然后安装了最新的 babel loader ,配置了.babelrc

{
    "presets": ["react"]
}
npm install -D babel-loader @babel/core @babel/preset-env webpack

结果出现了错误提示:

ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module 'babel-preset-react' from '/Users/guohaidong/Documents/demospace/react-demo/webpack-demo/webpack-to-upload'
- If you want to resolve "react", use "module:react"
- Did you mean "@babel/react"?

确定了问题为babel不兼容
查找npm 中 babel/preset-react 发现已经两年没有更新了,然后使了"@babel/preset-react": "^7.0.0",配置了.babelrc

{
    "presets": ["@babel/preset-react"]
}

build success

创建成功

你可能感兴趣的:(webpack 搭建react应用-babel不兼容)