react项目升级报错,babel报错,babelrc配置兼容等问题如何解决

2023-05-24,,

这篇“react项目升级报错,babel报错,babelrc配置兼容等问题如何解决”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“react项目升级报错,babel报错,babelrc配置兼容等问题如何解决”文章吧。

react项目升级报错,babel报错,.babelrc配置兼容问题

遇到问题

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配置兼容等问题如何解决”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注本站行业资讯频道。

《react项目升级报错,babel报错,babelrc配置兼容等问题如何解决.doc》

下载本文的Word格式文档,以方便收藏与打印。