日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

react項目升級報錯,babel報錯,.babelrc配置兼容等問題及解決_React

作者:daoke_li ? 更新時間: 2022-10-03 編程語言

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

再運行時項目就跑起來了。

原文鏈接:https://blog.csdn.net/daoke_li/article/details/126120339

欄目分類
最近更新