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’
react运行报错TypeError
报错:TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string.
在同事帮忙下已解决,
现记录一下思路
页面 / 控制台报错
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at validateString (internal/validators.js:117:11)
at Object.join (path.js:375:7)
at noopServiceWorkerMiddleware (D:\git\healthyWashing\node_modules\react-dev-utils\noopServiceWorkerMiddleware.js:14:26)
……
根据提示,看出问题是在react-dev-utils下面的noopServiceWorkerMiddleware里,
全局搜索‘"react-dev-utils"’,注意有双引号,找到node_modules/react-scripts/package.json文件中的"react-dev-utils": "^10.0.0",这一行。
考虑到可能是没有锁定版本,最近有包有更新后造成bug的可能,所以去掉尖角号^,
然后 清除缓存并重新安装依赖
npm cache clean --force npm install
再运行时项目就跑起来了。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
查看更多关于react项目升级报错,babel报错,.babelrc配置兼容等问题及解决的详细内容...