当使用一些github上他人开发的老项目时,由于依赖包的版本比较旧,在npm install时就可能会遇到一些奇怪的报错问题。
比如这里clone完工程文件后,在运行npm install时报错
gyp ERR! build error
gyp ERR! stack Error: `C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0BinMSBuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:DevelopEnvironmentnodejsnode_modulesnpmnode_modulesnode-gyplibbuild.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:DevelopWorkspaceJavascriptsimple-excel-parser-electronnode_moduleslibxmljs
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:DevelopEnvironmentnodejsnode.exe C:DevelopEnvironmentnodejsnode_modulesnpmnode_modulesnode-gypbinnode-gyp.js build --fallback-to-build --loglevel=http --module=C:DevelopWorkspaceJavascriptsimple-excel-parser-electronnode_moduleslibxmljsbuildReleasexmljs.node --module_name=xmljs --module_path=C:DevelopWorkspaceJavascriptsimple-excel-parser-electronnode_moduleslibxmljsbuildRelease --napi_version=8 --node_abi_napi=napi' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (C:DevelopWorkspaceJavascriptsimple-excel-parser-electronnode_moduleslibxmljsnode_modulesnode-pre-gyplibutilcompile.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:DevelopWorkspaceJavascriptsimple-excel-parser-electronnode_moduleslibxmljs
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:DevelopEnvironmentnodejsnode.exe C:DevelopEnvironmentnodejsnode_modulesnpmnode_modulesnode-gypbinnode-gyp.js build --fallback-to-build --loglevel=http --module=C:DevelopWorkspaceJavascriptsimple-excel-parser-electronnode_moduleslibxmljsbuildReleasexmljs.node --module_name=xmljs --module_path=C:DevelopWorkspaceJavascriptsimple-excel-parser-electronnode_moduleslibxmljsbuildRelease --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:UsersAdministratorAppDataRoamingnpm-cache_logs2023-03-08T04_06_31_972Z-debug.log
这里报错说的是在安装libxmljs的时候出现了错误,但是查看自己的package.json文件,里面并没有写到对libxmljs的依赖。
解决方法
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 实用技巧
原文地址:https://blog.csdn.net/feiniao8651/article/details/129400920
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_15679.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。