【问题标题】:Problem with node-gyp on windows: configure errorWindows 上的 node-gyp 问题:配置错误
【发布时间】:2023-04-03 10:55:01
【问题描述】:

我想为 node 安装 bcrypt 包,但是 node-gyp 有问题。

我安装了“Visual Studio Build Tools 2017” (C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools) 以及 Python 2.7.16 (C:/Python27/python.exe)

完整的控制台输出:

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

我想在我的节点项目中使用 bcrypt,它适用于 Arch,但不适用于 Windows。

【问题讨论】:

    标签: node.js windows npm bcrypt node-gyp


    【解决方案1】:

    我不太确定我做了什么,但这为我解决了问题。

    我卸载了

    • NodeJS
    • Visual Studio 安装程序中的所有内容

    我删除了我能找到的所有对 npm/node 的引用 (%appdata%/npm, %temp%) 重新安装 Node,通过npm install -g node-gyp & `npm install --global --production windows-build-tools 安装 node-gyp。还是不行。

    但后来我安装了 Visual Studio 2019 并且它工作正常。

    【讨论】:

      【解决方案2】:

      以管理员身份运行 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
      

      如果要使用命令提示符,则需要使用“导出”的等效项。

      【讨论】:

      • 我看到你也看到了这个帖子:github.com/nodejs/node-gyp/issues/1842 不幸的是,该命令为我在 C:/Python27 下安装了 python,并且在设置 PYTHON 环境变量后我仍然得到同样的错误,即无法执行。
      • 如果我手动将文件夹 Python27 移动到 windows-build-tools 并让环境变量指向那里,node-gyp 仍然在 C:\python27 下查找并给我它找不到 python 的错误那里(在运行 npm install 时)。
      • @Phil 当我处理这个时,构建工具安装在我提到的路径中。但是,如果它为您安装到不同的位置,您只需更新第二行即可。如果它在您指定的其他位置查找,请确保您的计算机上没有其他同名的变量。
      • 实际上它现在工作了。问题是自动安装全局 .npmrc 中的 python 路径(在 appdata/roaming/npm/etc 文件夹中)。因此,在 windows-build-tools 中手动将其设置为需要在 windows 环境变量(或 bash_profile)中这样做,并将其从 npm 配置中删除。可以使用以下命令找到全局 npm 配置:npm config get globalconfig
      猜你喜欢
      • 2023-04-07
      • 2022-08-11
      • 2015-12-04
      • 1970-01-01
      • 2018-03-28
      • 2013-05-25
      • 2019-12-23
      相关资源
      最近更新 更多