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

创建成功

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容