广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >react项目升级报错,babel报错,.babelrc配置兼容等问题及解决
  • 631
分享到

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

react项目升级报错reactbabel报错babelrc配置兼容 2022-11-13 14:11:12 631人浏览 安东尼
摘要

目录React项目升级报错,babel报错,.babelrc配置兼容问题遇到问题最终解决方案react运行报错TypeError现记录一下思路react项目升级报错,babel报错,

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

再运行时项目就跑起来了。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: react项目升级报错,babel报错,.babelrc配置兼容等问题及解决

本文链接: https://www.lsjlt.com/news/172142.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作