最近在npm install 的时候遇到一个奇怪的错误,找了很久都没找到原因,错误是:
npm ERR! code 1
npm ERR! path D:\htz\web\htz_web_app\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@16.7.0 | win32 | x64
npm ERR! (node:6764) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp info spawn C:\Python27\python.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args 'D:\\htz\\web\\htz_web_app\\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 '-G',
npm ERR! gyp info spawn args 'msvs_version=2017',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'D:\\htz\\web\\htz_web_app\\node_modules\\node-sass\\build\\config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'D:\\htz\\web\\htz_web_app\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'C:\\Users\\Administrator\\.node-gyp\\16.7.0\\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\\Administrator\\.node-gyp\\16.7.0',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=D:\\htz\\web\\htz_web_app\\node_modules\\node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=C:\\Users\\Administrator\\.node-gyp\\16.7.0\\<(target_arch)\\node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=D:\\htz\\web\\htz_web_app\\node_modules\\node-sass',
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 'D:\\htz\\web\\htz_web_app\\node_modules\\node-sass\\build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! Traceback (most recent call last):
npm ERR! File "D:\htz\web\htz_web_app\node_modules\node-gyp\gyp\gyp_main.py", line 16, in <module>
npm ERR! sys.exit(gyp.script_main())
npm ERR! File "D:\htz\web\htz_web_app\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 545, in script_main
npm ERR! return main(sys.argv[1:])
npm ERR! File "D:\htz\web\htz_web_app\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 538, in main
npm ERR! return gyp_main(args)
npm ERR! File "D:\htz\web\htz_web_app\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 514, in gyp_main
npm ERR! options.duplicate_basename_check)
npm ERR! File "D:\htz\web\htz_web_app\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 98, in Load
npm ERR! generator.CalculateVariables(default_variables, params)
npm ERR! File "D:\htz\web\htz_web_app\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 1916, in CalculateVariables
npm ERR! generator_flags.get('msvs_version', 'auto'))
npm ERR! File "D:\htz\web\htz_web_app\node_modules\node-gyp\gyp\pylib\gyp\MSVSVersion.py", line 434, in SelectVisualStudioVersion
npm ERR! versions = _DetectVisualStudioVersions(version_map[version], 'e' in version)
npm ERR! KeyError: '2017'
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack at ChildProcess.onCpExit (D:\htz\web\htz_web_app\node_modules\node-gyp\lib\configure.js:345:16)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:394:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Windows_NT 10.0.19042
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\htz\\web\\htz_web_app\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd D:\htz\web\htz_web_app\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.7.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache\_logs\2021-09-02T14_15_40_335Z-debug.log
npm版本无需单独安装,卸载后重新下载对应版本的nodejs重新安装即可。
下载地址:
https://nodejs.org/zh-cn/download/releases/
我选择的是
https://nodejs.org/download/release/v14.16.1/node-v14.16.1-x64.msi
重新安装后再次运行npm install 上面问题完美解决。
>npm -v
6.14.12
>node -v
v14.16.1