在我的应用程序上运行“npm更新”之后,我突然收到以下错误:
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;真奇怪。因此,我将其与运行在不同工作站上的相同应用程序进行比较,使用相同的代码,但在我使用而不是的地方,运行的是“npm更新”。这个应用程序起作用了,没什么好惊讶的。
我见过其他帖子也有这个错误,但它们的解决方案似乎不适用于我的环境。
我不明白为什么它不能在我的主工作站上工作。如果我从工作站复制node_modules,应用程序就会启动良好。但是,一旦我删除node_modules和Packy-lock.json并重新安装,应用程序就不会启动。我已经删除了node_modules/Packy-lock.json/清除npm缓存。帮不上忙。
我正在通过'npm‘比较模块版本,它们在两个工作站上都是相同的。
它们都运行着NodeJS 8.12.0和NPM8.19.2。
我查看了它正在错误运行的文件(pako/lib/zlib/trees.js),在这两个系统上都是相同的。
我不知道什么是'pako‘,但使用'npm解释帕克’似乎与pdf-lib有关,后者从未更新过。
我的应用程序是用创建-反应-应用程序构建的。
我完全不知所措。这是我的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"
}
}发布于 2022-11-05 13:05:55
我做了个解决办法。我比较了我的项目的旧的和新的package-lock.json,并看到一些@babel版本更改为v7.20.2 (2022年11月4日)。我用旧的一个覆盖了新的package-lock.json,我的react应用程序又成功地运行了。
然后,我在我的package.json中更改(降级)了一些@babel包,它解决了这个问题:
将这一行放入您的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",发布于 2022-11-07 15:21:26
https://github.com/babel/babel/issues/15132
巴贝尔解决了他们的问题。您可以使用最新的版本,它现在应该可以工作。(我核实了)
发布于 2022-11-07 12:25:49
扩展@Attila的答案,如果您正在使用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"
}
}https://stackoverflow.com/questions/74323826
复制相似问题