react項目升級報錯,babel報錯,.babelrc配置兼容等問題及解決
react項目升級報錯,babel報錯,.babelrc配置兼容問題
由于開發(fā)環(huán)境和項目版本的兼容問題,嘗試升級了react-scripts后,一大堆問題接踵而至,翻遍了百度和csdn,往往解決了舊的又出現(xiàn)新的,或者開發(fā)沒問題而打包時報錯,現(xiàn)羅列一下遇到的主要問題和最終解決方案,以供參考。
遇到問題
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.
在同事幫忙下已解決,
現(xiàn)記錄一下思路
頁面 / 控制臺報錯
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)
……
根據(jù)提示,看出問題是在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
再運行時項目就跑起來了。
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用React Profiler進行性能優(yōu)化方案詳解
在現(xiàn)代前端開發(fā)中,性能優(yōu)化是一個不可忽視的重要環(huán)節(jié),在 React 生態(tài)系統(tǒng)中,React Profiler 是一個強大的工具,下面我們來看看如何使用它來提升我們的 React 應(yīng)用吧2025-03-03
React-Route6實現(xiàn)keep-alive效果
本文主要介紹了React-Route6實現(xiàn)keep-alive效果,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧<BR>2022-06-06
react如何修改循環(huán)數(shù)組對象的數(shù)據(jù)
這篇文章主要介紹了react如何修改循環(huán)數(shù)組對象的數(shù)據(jù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12
40行代碼把Vue3的響應(yīng)式集成進React做狀態(tài)管理
這篇文章主要介紹了40行代碼把Vue3的響應(yīng)式集成進React做狀態(tài)管理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-05-05

