今天使用 npm run build
生成项目时突然报如下错误:
fs.js:35
} = primordials;
^
ReferenceError: primordials is not defined
at fs.js:35:5
at req_ (D:\Idea2019\gcfuture\monitor-ui\node_modules\natives\index.js:143:24)
at Object.req [as require] (D:\Idea2019\gcfuture\monitor-ui\node_modules\natives\index.js:55:10)
at Object.<anonymous> (D:\Idea2019\gcfuture\monitor-ui\node_modules\vinyl-fs\node_modules\graceful-fs\fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `ice build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! D:\develop\nodejs\node_cache\_logs\2021-03-24T06_15_22_463Z-debug.log
尝试了很多方法没有解决,具体方法如下:
第一种方案
//清理缓存
npm cache clean --force
//删除已下载模块
rm -rf node_modules
//删除package-lock.json文件
rm -rf package-lock.json
//重新下载依赖
npm install
第一种方案解决 npm ERR! code ELIFECYCLE
这个问题应该可以。
第二种方案
修改package.json文件,添加如下配置
// Your current package.json
"scripts": {
// Your current package.json scripts
"preinstall": "npx npm-force-resolutions"
},
"resolutions": {
"graceful-fs": "^4.2.4"
}
配置完成后,再次执行 npm install
,完成后再执行 npm run build
完美解决。