无法在Centos服务器上安装bcrypt Node.js模块

8

我正在尝试在CentOS服务器上安装bcrypt,但遇到以下错误:

info postuninstall bcrypt@0.5.0
ERR! bcrypt@0.5.0 install: `make build`
ERR! `sh "-c" "make build"` failed with 2
ERR!
ERR! Failed at the bcrypt@0.5.0 install script.
ERR! This is most likely a problem with the bcrypt package,
ERR! not with npm itself.
ERR! Tell the author that this fails on your system:
ERR!     make build
ERR! You can get their info via:
ERR!     npm owner ls bcrypt
ERR! There is likely additional logging output above.
ERR!
ERR! System Linux 2.6.18-028stab095.1
ERR! command "nodejs" "/usr/bin/npm" "install" "bcrypt"
ERR! cwd /root/grouplo
ERR! node -v v0.6.15
ERR! npm -v 1.1.16
ERR! code ELIFECYCLE
ERR! message bcrypt@0.5.0 install: `make build`
ERR! message `sh "-c" "make build"` failed with 2
ERR! errno {}

我该怎么做来解决这个问题? 谢谢,
5个回答

14

还有一个原生的js版本的bcrypt,不需要编译。 https://github.com/shaneGirish/bcrypt-nodejs

npm install bcrypt-nodejs

这个 API 非常类似于编译版本。以下内容直接摘自自述文件。

基本用法:

同步

var hash = bcrypt.hashSync("bacon");

bcrypt.compareSync("bacon", hash); // true
bcrypt.compareSync("veggies", hash); // false

异步

bcrypt.hash("bacon", null, null, function(err, hash) {
    // Store hash in your password DB.
});

// Load hash from your password DB.
bcrypt.compare("bacon", hash, function(err, res) {
    // res == true
});
bcrypt.compare("veggies", hash, function(err, res) {
    // res = false
});

1
bcrypt真是个头疼的问题,我正在迁移到这个。感谢提供的替代方案。 - Eat at Joes

7

对我而言,解决办法是确保我已经安装了gcc、openssl和node-gyp。

要安装gcc和openssl,请使用yum:

sudo yum install gcc-c++ openssl-devel

要全局安装node-gyp,请使用npm:

npm install -g node-gyp

然后在Centos上,bcrypt的npm安装很顺利地完成了。


5

我在执行npm install bcrypt时遇到了同样的问题。另一个选择是从源代码进行安装。

git clone git://github.com/ncb000gt/node.bcrypt.js.git
cd node.bcrypt.js
node-gyp configure
node-gyp build

将node.bcrypt.js文件夹重命名为bcrypt,并将其移动到项目的node_modules文件夹中。您可以通过运行npm install -g node-gyp来安装node-gyp(-g表示全局安装)。

2
我认为我的系统缺少openssl。安装后,我的问题得到了解决。 - Feras Odeh
1
直到我安装了其他预先要求的内容之后,这才对我起作用,这让npm install能够正常工作。但是,你肯定给了我一个思路,让我知道该往哪个方向去。因此,我会点赞并发布另一种解决方案。 - iandotkelly

2
“bcrypt”的预构建二进制文件通常在发布新版本后的几个小时内或发布新的NodeJS版本后的几天内就可以获得。
但是,请记住,二进制文件仅作为方便提供。
如果您看到以下错误:
`You need the following packages on CentOS / RHEL / Fedora
- `gcc-c++` - 为了安装编译器链以编译节点模块。 - `make` - 通过node-gyp运行生成的Makefile,该Makefile按顺序调用编译器 - `python` - RHEL和CentOS已安装所需版本的python
请确保使用此命令安装所有依赖项,
`yum install -y gcc-c++ make`
然后继续进行bcrypt安装。
有关其他系统,请参见:https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions

0

我也遇到了这个问题,后来发现我的nodebcrypt不兼容。我使用的是node版本lts 12,但是我的package.json中的bcrypt版本是5,必须是3

您可以在这里检查node和bcrypt不同版本之间的兼容性。

希望能帮助到某些人。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接