简体   繁体   English

Windows 上的 node-gyp 问题:配置错误

[英]Problem with node-gyp on windows: configure error

I want to install the bcrypt package for node, but I have problems with node-gyp.我想为 node 安装 bcrypt 包,但是 node-gyp 有问题。

I have the "Visual Studio Build Tools 2017" installed ( C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools ), aswell as Python 2.7.16 ( C:/Python27/python.exe )我安装了“Visual Studio Build Tools 2017”( C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools )以及 Python 2.7.16 ( C:/Python27/python.exe

Full console output:完整的控制台输出:

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.6/bcrypt_lib-v3.0.6-node-v72-win32-x64-unknown.tar.gz
node-pre-gyp WARN Pre-built binaries not found for bcrypt@3.0.6 and node@12.4.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
Traceback (most recent call last):
  File "X:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py", line 16, in <module>
    sys.exit(gyp.script_main())
  File "X:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 545, in script_main
    return main(sys.argv[1:])
  File "X:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 538, in main
    return gyp_main(args)
  File "X:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 514, in gyp_main
    options.duplicate_basename_check)
  File "X:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 98, in Load
    generator.CalculateVariables(default_variables, params)
  File "X:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 1916, in CalculateVariables
    generator_flags.get('msvs_version', 'auto'))
  File "X:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\MSVSVersion.py", line 434, in SelectVisualStudioVersion
    versions = _DetectVisualStudioVersions(version_map[version], 'e' in version)
KeyError: '2017'
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (X:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:345:16)
gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "X:\\Program Files\\nodejs\\node.exe" "X:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--fallback-to-build" "--module=X:\\code\\toDoList\\node_modules\\bcrypt\\lib\\binding\\bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=X:\\code\\toDoList\\node_modules\\bcrypt\\lib\\binding" "--napi_version=4" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v72" "--python=c:\\Python27\\python.exe" "--msvs_version=2017"
gyp ERR! cwd X:\code\toDoList\node_modules\bcrypt
gyp ERR! node -v v12.4.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'X:\Program Files\nodejs\node.exe X:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=X:\code\toDoList\node_modules\bcrypt\lib\binding\bcrypt_lib.node --module_name=bcrypt_lib --module_path=X:\code\toDoList\node_modules\bcrypt\lib\binding --napi_version=4 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72 --python=c:\Python27\python.exe --msvs_version=2017' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (X:\code\toDoList\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
node-pre-gyp ERR! System Windows_NT 10.0.18362
node-pre-gyp ERR! command "X:\\Program Files\\nodejs\\node.exe" "X:\\code\\toDoList\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd X:\code\toDoList\node_modules\bcrypt
node-pre-gyp ERR! node -v v12.4.0
node-pre-gyp ERR! node-pre-gyp -v v0.12.0
node-pre-gyp ERR! not ok
npm WARN todolist@0.1.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@3.0.6 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@3.0.6 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\admin\AppData\Roaming\npm-cache\_logs\2019-06-21T15_27_23_192Z-debug.log

I want to use bcrypt in my node project, it works on Arch but not on Windows.我想在我的节点项目中使用 bcrypt,它适用于 Arch 但不适用于 Windows。

I'm not quite sure what I have done, but this fixed it for me.我不太确定我做了什么,但这为我解决了问题。

I uninstalled我卸载了

  • NodeJS节点JS
  • Everything in the Visual Studio Installer Visual Studio 安装程序中的所有内容

I removed every refrence to npm/node I could find (%appdata%/npm, %temp%) reinstalled Node, installed node-gyp via npm install -g node-gyp & npm install --global --production windows-build-tools .我删除了我能找到的所有对 npm/node 的引用 (%appdata%/npm, %temp%) 重新安装了 Node,通过npm install -g node-gyp gyp & npm install --global --production windows-build-tools node-gyp npm install --global --production windows-build-tools Still didn't work.仍然没有工作。

But then I installed Visual Studio 2019 and it worked.但后来我安装了 Visual Studio 2019 并且它工作正常。

Run Git Bash as Adminstrator以管理员身份运行 Git Bash

npm install --global --production windows-build-tools node-gyp
PYTHON='C:\\Users\\[YOUR USER]\\.windows-build-tools\\python27\\python.exe'
export PYTHON
npm config set PYTHON

If you want to use command prompt, you need to use the equivalent of "export".如果要使用命令提示符,则需要使用“导出”的等效项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM