react项目升级报错、babel报错,.babelrc配置兼容等问题
react项目升级报错、babel报错,.babelrc配置兼容等问题
由于开发环境和项目版本的兼容问题,尝试升级了react-scripts后,一大堆问题接踵而至,翻遍了百度和csdn,往往解决了旧的又出现新的,或者开发没问题而打包时报错,现罗列一下遇到的主要问题和最终解决方案,以供参考。
遇到问题
digital envelope routines::unsupported
命令行运行 $env:NODE_OPTIONS=“–openssl-legacy-provider” ,再次启动即可
Parsing error: This experimental syntax requires enabling one of the following parser plugin(s): “decorators-legacy”, “decorators”.
require() of ES Module ……is not supported.
Parsing error: This experimental syntax requires enabling one of the following parser plugin(s): “decorators-legacy”, “decorators”.
[eslint] The “path” argument must be of type string. Received an instance of Array
[eslint] ESLint configuration in .eslintrc is invalid:
- Unexpected top-level property “babel”.
最终解决方案
删掉根目录下的.babelrc文件,在package.json中配置:
"babel": {"presets": ["react-app"],"plugins": [["@babel/plugin-proposal-decorators",{"legacy": true}]]},
必要时安装依赖:“@babel/eslint-parser”
注
babel-eslint 自 2020 年 3 月起已被弃用。 该软件包已迁移到新的仓库,如有需要请查阅 ‘@babel/eslint-parser’
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
