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

具体错误如下:

npm ERR! code 1
npm ERR! path F:\vueproject\echarts_demo\koa_server\node_modules\bufferutil
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.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\\node-gyp\\Cache\\10.22.1\\x64\\node.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x433943 [F:\vueproject\echarts_demo\koa_server\node_modules\bufferutil\build\bufferutil.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:\python38\python.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:\python38\python.exe
npm ERR! gyp info spawn args [ 'D:\\Program Files\\nodejs\\node_global\\node_modules\\npm\\node_modules\\node-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\\node_modules\\bufferutil\\build\\config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'D:\\Program Files\\nodejs\\node_global\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\ASUS\\AppData\\Local\\node-gyp\\Cache\\10.22.1\\include\\node\\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\\node-gyp\\Cache\\10.22.1',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=D:\\Program Files\\nodejs\\node_global\\node_modules\\npm\\node_modules\\node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\ASUS\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\10.22.1\\\\<(target_arch)\\\\node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=F:\\vueproject\\echarts_demo\\koa_server\\node_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\\node_modules\\bufferutil\\build',
npm ERR! gyp info spawn args   '-Goutput_dir=.' ]
npm ERR! gyp info spawn C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.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\14.0\bin\MSBuild.exe` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onExit (D:\Program Files\nodejs\node_global\node_modules\npm\node_modules\node-gyp\lib\build.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:\\nvm\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_global\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd F:\vueproject\echarts_demo\koa_server\node_modules\bufferutil
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\nodejs\node_cache\_logs\2021-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,然后点击右下角的编辑,最终进入以下这个界面。

最后根据python在自己电脑上安装的位置进行配置,我的安装位置是在:F:\python38。

5、在cmd命令窗口中输入python,如果出现以下结果则说明环境配置成功。

6、在cmd窗口中输入node-gyp list,出现以下结果,则说明安装成功。

最后就可以成功的使用npm下载第三方插件啦。

参考文章

https://blog.csdn.net/weixin_30600503/article/details/101811489

Logo

鸿蒙生态一站式服务平台。

更多推荐