gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp

npm i bcrypt

新系统拉取项目,下载依赖包,其中包含 bcrypt 依赖,一直安装不成功。

gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp

github issues  同样的问题,可能生效的不同的方法

----

换了台电脑又遇到了,这次是回退 npm版本解决的问题。

---

已安装号 Python 3 和 Visual Studio 2019。

此类型npm库都会使用到 node-gyp ,依赖 Python 和 Visual Studio 

npm ERR! gyp info using node-gyp@8.2.0
npm ERR! gyp info using node@14.18.1 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.0 found at "C:Program FilesPython310python.exe"
npm ERR! gyp info find VS using VS2019 (16.11.31729.503) found at:
npm ERR! gyp info find VS "C:Program Files (x86)Microsoft Visual Studio2019Community"
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn C:Program FilesPython310python.exe

最终卡在

npm ERR! gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp
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 (C:Users17212AppDataRoaming
pm
ode_modules
pm
ode_modules
ode-gyplibconfigure.js:353:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:282:12)

尝试过清缓存,重装,没用。

npm cache clean -f
npm uninstall node-gyp -g
npm install node-gyp -g

使用,还是没用

再次尝试,没效果。还是使用了Python 3,卸载了Python 3,程序报错Python2不适用,必须要Python 3。
npm config set python C:Python27python.exe

安装 Visual Studio 2017,设置 2017 ,也没用。

npm config set msvs_version 2017 --global

最后到用户目录删除了文件重新安装,成功了。

删除文件:C:Users***AppDataRoaming pm-cache、C:Users***AppDataRoaming pm ode_modules pm、C:Users***AppDataRoaming pm ode_modules ode-gyp

只剩下了先前安装的 windows-build-tools(使用了管理员shell安装)

> bcrypt@5.0.1 install E:workspacecargo-mongo
ode_modulescrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! install request to https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.0.1/bcrypt_lib-v5.0.1-napi-v3-win32-x64-unknown.tar.gz failed, reason: read ECONNRESET 
node-pre-gyp WARN Pre-built binaries not installable for bcrypt@5.0.1 and node@14.18.1 (node-v83 ABI, unknown) (falling back to source compile with node-gyp) 
node-pre-gyp WARN Hit error request to https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.0.1/bcrypt_lib-v5.0.1-napi-v3-win32-x64-unknown.tar.gz failed, reason: read ECONNRESET 
在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
  nothing.c
  win_delay_load_hook.cc
  nothing.vcxproj -> E:workspacecargo-mongo
ode_modulescryptuildRelease\nothing.lib
  blowfish.cc
  bcrypt.cc
  bcrypt_node.cc
  win_delay_load_hook.cc
    正在创建库 E:workspacecargo-mongo
ode_modulescryptuildReleasecrypt_lib.lib 和对象 E:workspacecargo-mongo
ode_modulescryptuildReleas
  ecrypt_lib.exp
  bcrypt_lib.vcxproj -> E:workspacecargo-mongo
ode_modulescryptuildRelease\bcrypt_lib.node
  Copying E:workspacecargo-mongo
ode_modulescryptuildRelease/bcrypt_lib.node to E:/workspace/cargo-mongo/node_modules/bcrypt/lib/binding
  /napi-v3crypt_lib.node
  已复制         1 个文件。

> nodemon@1.19.4 postinstall E:workspacecargo-mongo
ode_modules
odemon
> node bin/postinstall || exit 0

Love nodemon? You can now support the project via the open collective:
 > https://opencollective.com/nodemon/donate

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modulesfsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ bcrypt@5.0.1
added 46 packages from 110 contributors and updated 411 packages in 100.985s

18 packages are looking for funding
  run `npm fund` for details

感觉本次可能是 管理员权限打开powershell 运行 

npm install --global --production windows-build-tools

在起作用。但是其他的尝试可能会在其他时候适用。

bcrypt 仓库文档安装说明地址。

github issues

原文地址:https://www.cnblogs.com/jiayouba/p/15436827.html