這篇文章與一個快速變化的事件有關。
在我的應用程式上運行“npm update”后,我突然收到以下錯誤:
Compiled with problems:
ERROR in ./node_modules/pako/lib/zlib/trees.js 257:106
Module parse failed: Unexpected token (257:106)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| * not null.
| */
> function gen_bitlen(s, desc) /* deflate_state *s;*/ /* tree_desc *desc; /* the tree descriptor */*/{
| var tree = desc.dyn_tree;
| var max_code = desc.max_code;
奇怪的。因此,我將它與在不同作業站上運行的具有相同代碼的相同應用程式進行了比較,但我沒有。該應用程式有效,不足為奇。
我看過其他有此錯誤的帖子,但他們的解決方案似乎不適用于我的環境。
我無法弄清楚為什么它不能在我的主作業站上作業。如果我從作業站復制 node_modules,則應用程式可以正常啟動。但是一旦我洗掉 node_modules 和 package-lock.json 并重新安裝,該應用程式將無法啟動。我已經洗掉了 node_modules/package-lock.json/clear npm 快取。沒有幫助。
我正在通過“npm ls”比較模塊版本,它們在兩個作業站上都??是相同的。
兩者都在運行 NodeJS 8.12.0 和 npm 8.19.2
我查看了出錯的檔案 (pako/lib/zlib/trees.js),它在兩個系統上都是相同的。
我不知道“pako”是什么,但使用“npm explain pako”似乎與從未更新過的 pdf-lib 有關。
我的應用是用 create-react-app 構建的。
我完全不知所措。這是我的 package.json:
{
"name": "foo",
"version": "0.1.0",
"description": "Foo",
"contributors": [],
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@coreui/chartjs": "^2.0.0",
"@coreui/coreui-pro": "^3.4.2",
"@coreui/icons": "^2.1.0",
"@coreui/icons-pro": "^2.0.3",
"@coreui/icons-react": "^1.1.0",
"@coreui/react": "^3.4.6",
"@coreui/react-chartjs": "^1.1.0",
"@coreui/utils": "^1.3.1",
"@fortawesome/fontawesome-free-solid": "^5.0.13",
"@fortawesome/fontawesome-svg-core": "^6.1.1",
"@fortawesome/free-regular-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.1.18",
"@nadavshaar/react-grid-table": "^1.0.0",
"@pdf-lib/fontkit": "^1.1.1",
"@react-firebase/auth": "^0.2.10",
"ag-grid-community": "^25.3.0",
"ag-grid-react": "^25.3.0",
"arithmetic": "^1.0.1",
"bootstrap": "^5.2.0",
"classnames": "^2.3.1",
"codemirror": "^5.63.3",
"core-js": "^3.19.1",
"downloadjs": "^1.4.7",
"firebase": "^9.12.1",
"firebase-admin": "^11.0.1",
"firebaseui": "^6.0.1",
"formik": "^2.2.9",
"mobx": "^6.3.3",
"mobx-react": "^7.1.0",
"pdf-lib": "^1.17.1",
"prop-types": "^15.7.2",
"random-id": "^1.0.4",
"react": "^17.0.2",
"react-app-polyfill": "^2.0.0",
"react-awesome-button": "^6.5.1",
"react-big-calendar": "^0.33.6",
"react-bootstrap": "^2.4.0",
"react-collapsible": "^2.10.0",
"react-cookie-consent": "^8.0.1",
"react-dom": "^17.0.2",
"react-firebase-hooks": "^5.0.3",
"react-firebaseui": "^6.0.0",
"react-grid-layout": "^1.3.0",
"react-range": "^1.8.12",
"react-redux": "7.2.4",
"react-router-dom": "^5.3.0",
"react-select": "^4.3.1",
"react-text-mask-hoc": "^0.11.0",
"react-toastify": "^9.0.8",
"reactstrap": "^8.10.0",
"redux": "4.1.0",
"rpg-dice-roller": "1.6.0",
"sass": "^1.55.0",
"sillyname": "^0.1.0",
"spinkit": "2.0.1",
"string-math": "^1.2.2",
"styled-components": "^5.3.3",
"yup": "^0.32.11"
},
"devDependencies": {
"mutationobserver-shim": "^0.3.7",
"react-scripts": "^5.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test:cov": "npm test -- --coverage --watchAll=false",
"test:debug": "react-scripts --inspect-brk test --runInBand",
"eject": "react-scripts eject",
"zip": "git archive -o coreui-pro-react-admin-template-v$npm_package_version.zip -9 HEAD"
},
"bugs": {
"url": "https://github.com/coreui/coreui-free-react-admin-template/issues"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 10",
"not op_mini all"
],
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"!**/*index.js",
"!src/serviceWorker.js",
"!src/polyfill.js"
]
},
"engines": {
"node": ">=8.16",
"npm": ">=6"
}
}
uj5u.com熱心網友回復:
我做了一個解決方法。我比較了我的新舊package-lock.json專案,我看到一些 @babel lib 版本更改為 v7.20.2(2022 年 11 月 4 日)。我用舊的覆寫了新package-lock.json的,我的反應應用程式再次構建并成功運行。
然后我更改(降級)了我的一些 @babel 包,package.json它解決了問題:
將此行放入您的package.json檔案中:
"@babel/core": "7.19.6",
"@babel/generator": "7.19.6",
"@babel/compat-data": "7.19.4",
"@babel/helper-compilation-targets": "7.19.3",
"@babel/helper-create-class-features-plugin":"7.19.0",
"@babel/helper-module-transforms":"7.19.6",
uj5u.com熱心網友回復:
https://github.com/babel/babel/issues/15132
Babel 解決了他們的問題。您可以使用最新版本,它現在應該可以作業了。(我驗證過了)
uj5u.com熱心網友回復:
擴展@Attila Szombathelyi 的答案,如果您使用的是 CRA,您可以在您的package.json
{
"name": "app-name",
"version": "1.0.0",
"dependencies": {
...
},
...
"resolutions": {
"@babel/core": "7.19.6",
"@babel/generator": "7.19.6",
"@babel/compat-data": "7.19.4",
"@babel/helper-compilation-targets": "7.19.3",
"@babel/helper-create-class-features-plugin": "7.19.0",
"@babel/helper-module-transforms": "7.19.6",
"babel-loader": "8.2.5"
}
}
uj5u.com熱心網友回復:
我的解決方案是禁用 babel 依賴項轉譯(在我們的專案中啟用)。
我是怎么做到的?在我的專案中使用了 vue-cli。所以我禁用了transpileDependecies選項vue.config.js
如果你使用的是裸 webpack,你也可以為它或任何其他構建系統找到合適的解決方案。
uj5u.com熱心網友回復:
解決方法:從 npm 8.3.0 開始,您還可以 在 package.json 中使用 npm 的覆寫。洗掉 package-lock.json 和 node_modules 檔案夾(推薦)。
"overrides": {
"@babel/core": "7.19.6",
"@babel/generator": "7.19.6",
"@babel/compat-data": "7.19.4",
"@babel/helper-compilation-targets": "7.19.3",
"@babel/helper-create-class-features-plugin": "7.19.0",
"@babel/helper-module-transforms": "7.19.6"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/530109.html
標籤:反应npm创建反应应用
