npm install bcrypt 时可能会出现的一个错误:node-pre-gyp ERR!

时间:2024-03-25 21:49:12

node-pre-gyp ERR! Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v1.0.2/bcrypt_lib-v1.0.2-node-v64-win32-x64.tar.gz

node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v64 ABI) (falling back to source compile with node-gyp)

node-pre-gyp ERR! Tried to download(undefined): https://github.com/kelektiv/node.bcrypt.js/releases/download/v1.0.2/bcrypt_lib-v1.0.2-node-v64-win32-x64.tar.gz

node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v64 ABI) (falling back to source compile with node-gyp)

如上所示,百度了一些解决方法,github上说要先npm install --global --production windows-build-tools(管理员运行),然后Install Visual C++ Build Environment: Visual Studio Build Tools (using "Visual C++ build tools" workload) or Visual Studio 2017 Community (using the "Desktop development with C++" workload),再安装python2.7,并npm config set python python2.7,npm config set msvs_version 2017,node-gyp好像也要 -g install。但是并没用,还是没有解决,一天了。最后去npm官网找bcrypt的包,发现

npm install bcrypt 时可能会出现的一个错误:node-pre-gyp ERR!

这是版本兼容说明表,不同的node版本对应不同版本的bcrypt,我发现我之前的node版本是8.9(为了解决这个安装问题,期间升级了node10.16),而依赖里写的bcrypt版本是1.0.2,明显对不上,而现在我的node版本是10.16,依赖写的bcrypt版本还是1.0.2,这肯定不行啊,上面的表里node10,11版本对应的bcrypt版本是>=3,那就得把依赖改成3.0+,npm install ,就没再报错了。

总结一下,有些包的使用是需要其他的一些工具,甚至还要注意版本的兼容!