npm install报错问题的定位处理思路
Posted feiniao8651
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了npm install报错问题的定位处理思路相关的知识,希望对你有一定的参考价值。
当使用一些github上他人开发的老项目时,由于依赖包的版本比较旧,在npm install时就可能会遇到一些奇怪的报错问题。
比如这里clone完工程文件后,在运行npm install时报错
gyp ERR! build error
gyp ERR! stack Error: `C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin\\MSBuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\\Develop\\Environment\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\lib\\build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:400:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:282:12)
gyp ERR! System Windows_NT 10.0.15063
gyp ERR! command "C:\\\\Develop\\\\Environment\\\\nodejs\\\\node.exe" "C:\\\\Develop\\\\Environment\\\\nodejs\\\\node_modules\\\\npm\\\\node_modules\\\\node-gyp\\\\bin\\\\node-gyp.js" "build" "--fallback-to-build" "--loglevel=http" "--module=C:\\\\Develop\\\\Workspace\\\\javascript\\\\simple-excel-parser-electron\\\\node_modules\\\\libxmljs\\\\build\\\\Release\\\\xmljs.node" "--module_name=xmljs" "--module_path=C:\\\\Develop\\\\Workspace\\\\Javascript\\\\simple-excel-parser-electron\\\\node_modules\\\\libxmljs\\\\build\\\\Release" "--napi_version=8" "--node_abi_napi=napi"
gyp ERR! cwd C:\\Develop\\Workspace\\Javascript\\simple-excel-parser-electron\\node_modules\\libxmljs
gyp ERR! node -v v14.18.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'C:\\Develop\\Environment\\nodejs\\node.exe C:\\Develop\\Environment\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js build --fallback-to-build --loglevel=http --module=C:\\Develop\\Workspace\\Javascript\\simple-excel-parser-electron\\node_modules\\libxmljs\\build\\Release\\xmljs.node --module_name=xmljs --module_path=C:\\Develop\\Workspace\\Javascript\\simple-excel-parser-electron\\node_modules\\libxmljs\\build\\Release --napi_version=8 --node_abi_napi=napi' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (C:\\Develop\\Workspace\\Javascript\\simple-excel-parser-electron\\node_modules\\libxmljs\\node_modules\\node-pre-gyp\\lib\\util\\compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:400:28)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1058:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)
node-pre-gyp ERR! System Windows_NT 10.0.15063
node-pre-gyp ERR! command "C:\\\\Develop\\\\Environment\\\\nodejs\\\\node.exe" "C:\\\\Develop\\\\Workspace\\\\Javascript\\\\simple-excel-parser-electron\\\\node_modules\\\\libxmljs\\\\node_modules\\\\node-pre-gyp\\\\bin\\\\node-pre-gyp" "install" "--fallback-to-build" "--loglevel" "http"
node-pre-gyp ERR! cwd C:\\Develop\\Workspace\\Javascript\\simple-excel-parser-electron\\node_modules\\libxmljs
node-pre-gyp ERR! node -v v14.18.1
node-pre-gyp ERR! node-pre-gyp -v v0.9.1
node-pre-gyp ERR! not ok
Failed to execute 'C:\\Develop\\Environment\\nodejs\\node.exe C:\\Develop\\Environment\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js build --fallback-to-build --loglevel=http --module=C:\\Develop\\Workspace\\Javascript\\simple-excel-parser-electron\\node_modules\\libxmljs\\build\\Release\\xmljs.node --module_name=xmljs --module_path=C:\\Develop\\Workspace\\Javascript\\simple-excel-parser-electron\\node_modules\\libxmljs\\build\\Release --napi_version=8 --node_abi_napi=napi' (1)
npm WARN simplepaser_electron@1.0.0 No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! libxmljs@0.18.8 install: `node-pre-gyp install --fallback-to-build --loglevel http`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the libxmljs@0.18.8 install 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! C:\\Users\\Administrator\\AppData\\Roaming\\npm-cache\\_logs\\2023-03-08T04_06_31_972Z-debug.log
这里报错说的是在安装libxmljs的时候出现了错误,但是查看自己的package.json文件,里面并没有写到对libxmljs的依赖。
解决方法
使用npm list查看当前依赖树
npm list | grep libxmljs
输出结果中看到
npm ERR! missing: libxmljs@0.18.8, required by excel@1.0.0
而这里的excel库,正是package.json里写的依赖库。将这个依赖库去掉,删除node_modules目录,重新执行npm install,没有报错。这时再执行npm install --save excel,也能正常安装。
这可以作为一种类似问题的通用解决方案,当npm install报错没有头绪时,可以通过npm list来定位具体哪个包的依赖引起的,从而可以找到突破口。
参考:
如何查看给定NPM模块的依赖关系树?
你可能不知道的 Npm 实用技巧
以上是关于npm install报错问题的定位处理思路的主要内容,如果未能解决你的问题,请参考以下文章
npm项目install 偶有报错导致不能启动应用 一般解决办法记录
npm项目install 偶有报错导致不能启动应用 一般解决办法记录