前端|npm ERR command failednpm ERR command CWINDOWSsystem32cmd.exe d s c node-gyp rebuild

今天下午使用npm下载websocket时遇到了一个错误,可能是我实战经验太少了,这个错误找了一个多小时。在这过程中升级了node的版本、又重新安装了淘宝镜像…一系列,主要是刚开始我以为我之前安装的python已经配置好环境变量(我之前上课的时候一直都有在用python,所以没有理由怀疑这个),而且我主观的以为这刚python应该没有多大的关系,于是就在那些细节末节的错误中找错,结果找了…。
具体错误如下:

npm ERR! code 1 npm ERR! path F:ueprojectecharts_demokoa_server ode_modulesufferutil npm ERR! command failed npm ERR! command C:WINDOWSsystem32cmd.exe /d /s /c node-gyp rebuild npm ERR! ????????????????????????????????ò???????????????/m??????? npm ERR!bufferutil.c npm ERR!win_delay_load_hook.cc npm ERR! C:\Users\ASUS\AppData\Local

ode-gyp\Cache\10.22.1\x64
ode.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x433943 [F:ueprojectecharts_demokoa_server
ode_modulesufferutiluildufferutil.vcxproj]
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@10.22.1 | win32 | x64
npm ERR! gyp info find Python using Python version 3.8.0 found at “F:python38python.exe”
npm ERR! gyp info find VS using VS2015 (14.0) found at:
npm ERR! gyp info find VS “C:Program Files (x86)Microsoft Visual Studio 14.0”
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn F:python38python.exe
npm ERR! gyp info spawn args [ ‘D:\Program Files
odejs
ode_global
ode_modules
pm
ode_modules
ode-gyp\gyp\gyp_main.py’,
npm ERR! gyp info spawn args ‘binding.gyp’,
npm ERR! gyp info spawn args ‘-f’,
npm ERR! gyp info spawn args ‘msvs’,
npm ERR! gyp info spawn args ‘-I’,
npm ERR! gyp info spawn args ‘F:\vueproject\echarts_demo\koa_server
ode_modules\bufferutil\build\config.gypi’,
npm ERR! gyp info spawn args ‘-I’,
npm ERR! gyp info spawn args ‘D:\Program Files
odejs
ode_global
ode_modules
pm
ode_modules
ode-gyp\addon.gypi’,
npm ERR! gyp info spawn args ‘-I’,
npm ERR! gyp info spawn args ‘C:\Users\ASUS\AppData\Local
ode-gyp\Cache\10.22.1\include
ode\common.gypi’,
npm ERR! gyp info spawn args ‘-Dlibrary=shared_library’,
npm ERR! gyp info spawn args ‘-Dvisibility=default’,
npm ERR! gyp info spawn args ‘-Dnode_root_dir=C:\Users\ASUS\AppData\Local
ode-gyp\Cache\10.22.1’,
npm ERR! gyp info spawn args ‘-Dnode_gyp_dir=D:\Program Files
odejs
ode_global
ode_modules
pm
ode_modules
ode-gyp’,
npm ERR! gyp info spawn args ‘-Dnode_lib_file=C:\Users\ASUS\AppData\Local
ode-gyp\Cache\10.22.1\<(target_arch)
ode.lib’,
npm ERR! gyp info spawn args ‘-Dmodule_root_dir=F:\vueproject\echarts_demo\koa_server
ode_modules\bufferutil’,
npm ERR! gyp info spawn args ‘-Dnode_engine=v8’,
npm ERR! gyp info spawn args ‘–depth=.’,
npm ERR! gyp info spawn args ‘–no-parallel’,
npm ERR! gyp info spawn args ‘–generator-output’,
npm ERR! gyp info spawn args ‘F:\vueproject\echarts_demo\koa_server
ode_modules\bufferutil\build’,
npm ERR! gyp info spawn args ‘-Goutput_dir=.’ ]
npm ERR! gyp info spawn C:Program Files (x86)MSBuild .0inMSBuild.exe
npm ERR! gyp info spawn args [ ‘build/binding.sln’,
npm ERR! gyp info spawn args ‘/clp:Verbosity=minimal’,
npm ERR! gyp info spawn args ‘/nologo’,
npm ERR! gyp info spawn args ‘/p:Configuration=Release; Platform=x64’ ]
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: C:Program Files (x86)MSBuild .0inMSBuild.exe failed with exit code: 1
npm ERR! gyp ERR! stack at ChildProcess.onExit (D:Program Files
odejs
ode_global
ode_modules
pm
ode_modules
ode-gyplibuild.js:194:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:198:13)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
npm ERR! gyp ERR! System Windows_NT 10.0.17134
npm ERR! gyp ERR! command “D:
vm
odejs
ode.exe” “D:\Program Files
odejs
ode_global
ode_modules
pm
ode_modules
ode-gyp\bin
ode-gyp.js” “rebuild”
npm ERR! gyp ERR! cwd F:ueprojectecharts_demokoa_server
ode_modulesufferutil
npm ERR! gyp ERR! node -v v10.22.1
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok
npm ERR! A complete log of this run can be found in: npm ERR!D:Program Files odejs ode_cache_logs?1-06-21T07_13_10_307Z-debug.log

问题归根结底是我之前安装的python没有配置环境变量。
解决方法
1、window+R打开cmd命令窗口。
2、输入npm install -g node-gyp。
3、cmd配置以来,输入npm config set python python3.8.0(python根据自己电脑的版本)。
4、配置python环境变量。右键计算机打开属性,分别点击高级系统配置、环境变量,在系统环境变量中选择Path,然后点击右下角的编辑,最终进入以下这个界面。
前端|npm ERR command failednpm ERR command CWINDOWSsystem32cmd.exe d s c node-gyp rebuild
文章图片

最后根据python在自己电脑上安装的位置进行配置,我的安装位置是在:F:python38。
5、在cmd命令窗口中输入python,如果出现以下结果则说明环境配置成功。
前端|npm ERR command failednpm ERR command CWINDOWSsystem32cmd.exe d s c node-gyp rebuild
文章图片

6、在cmd窗口中输入node-gyp list,出现以下结果,则说明安装成功。
前端|npm ERR command failednpm ERR command CWINDOWSsystem32cmd.exe d s c node-gyp rebuild
文章图片

最后就可以成功的使用npm下载第三方插件啦。
参考文章
【前端|npm ERR command failednpm ERR command CWINDOWSsystem32cmd.exe d s c node-gyp rebuild】https://blog.csdn.net/weixin_30600503/article/details/101811489

    推荐阅读