使用npm安装bcrypt时出错

haw*_*ris 70 bcrypt node.js npm

我无法安装bcrypt使用npm我的机器上,因为我遇到了以下错误.我没有太多运气就一直在排除问题.您能否建议任何诊断或解决问题的步骤,以便我能npm install bcrypt成功运行?

Someones-Macbook:node_modules Cody$ npm install bcrypt
npm WARN package.json grunt-contrib-htmlmin@0.1.3 No README data
|
> bcrypt@0.7.7 install /Applications/MAMP/htdocs/richintime/ultimate-seed/node_modules/bcrypt
> node-gyp rebuild

child_process: customFds option is deprecated, use stdio instead.
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o
../src/bcrypt_node.cc:118:18: error: no member named 'Dispose' in 'v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function>
      >'
        callback.Dispose();
        ~~~~~~~~ ^
../src/bcrypt_node.cc:202:19: error: unknown type name 'uv_work_t'
void GenSaltAsync(uv_work_t* req) {
                  ^
../src/bcrypt_node.cc:219:24: error: unknown type name 'uv_work_t'
void GenSaltAsyncAfter(uv_work_t* req) {
                       ^
../src/bcrypt_node.cc:220:17: error: calling a protected constructor of class 'v8::HandleScope'
    HandleScope scope;
                ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:816:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/bcrypt_node.cc:228:44: error: no member named 'New' in 'v8::String'
        argv[0] = Exception::Error(String::New(baton->error.c_str()));
                                   ~~~~~~~~^
../src/bcrypt_node.cc:229:19: error: no matching function for call to 'Undefined'
        argv[1] = Undefined();
                  ^~~~~~~~~
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:305:28: note: candidate function not viable: requires single argument 'isolate', but no
      arguments were provided
  friend Handle<Primitive> Undefined(Isolate* isolate);
                           ^
../src/bcrypt_node.cc:232:19: error: no matching function for call to 'Undefined'
        argv[0] = Undefined();
                  ^~~~~~~~~
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:305:28: note: candidate function not viable: requires single argument 'isolate', but no
      arguments were provided
  friend Handle<Primitive> Undefined(Isolate* isolate);
                           ^
../src/bcrypt_node.cc:238:20: error: member reference type 'v8::Persistent<v8::Function>' is not a pointer; maybe you meant to use '.'?
    baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
    ~~~~~~~~~~~~~~~^~
                   .
../src/bcrypt_node.cc:238:22: error: no member named 'Call' in 'v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >'
    baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
    ~~~~~~~~~~~~~~~  ^
../src/bcrypt_node.cc:238:36: error: no member named 'GetCurrent' in 'v8::Context'
    baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
                          ~~~~~~~~~^
../src/bcrypt_node.cc:246:34: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
Handle<Value> GenerateSalt(const Arguments &args) {
                                 ^~~~~~~~~
                                 v8::internal::Arguments
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:127:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/bcrypt_node.cc:247:17: error: calling a protected constructor of class 'v8::HandleScope'
    HandleScope scope;
                ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:816:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/bcrypt_node.cc:249:32: error: type 'const v8::internal::Arguments' does not provide a subscript operator
    const ssize_t rounds = args[0]->Int32Value();
                           ~~~~^~
../src/bcrypt_node.cc:250:30: error: type 'const v8::internal::Arguments' does not provide a subscript operator
    const int rand_len = args[1]->Int32Value();
                         ~~~~^~
../src/bcrypt_node.cc:251:58: error: type 'const v8::internal::Arguments' does not provide a subscript operator
    Local<Function> callback = Local<Function>::Cast(args[2]);
                                                     ~~~~^~
../src/bcrypt_node.cc:255:45: error: 'New' is a private member of 'v8::PersistentBase<v8::Function>'
    baton->callback = Persistent<Function>::New(callback);
                                            ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:572:23: note: declared private here
  V8_INLINE static T* New(Isolate* isolate, T* that);
                      ^
../src/bcrypt_node.cc:255:57: error: too few arguments to function call, expected 2, have 1
    baton->callback = Persistent<Function>::New(callback);
                      ~~~~~~~~~~~~~~~~~~~~~~~~~         ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:572:3: note: 'New' declared here
  V8_INLINE static T* New(Isolate* isolate, T* that);
  ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8config.h:289:20: note: expanded from macro 'V8_INLINE'
# define V8_INLINE inline __attribute__((always_inline))
                   ^
../src/bcrypt_node.cc:259:5: error: unknown type name 'uv_work_t'
    uv_work_t* req = new uv_work_t;
    ^
../src/bcrypt_node.cc:259:26: error: unknown type name 'uv_work_t'
    uv_work_t* req = new uv_work_t;
                         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/bcrypt_lib/src/bcrypt_node.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Darwin 13.4.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Applications/MAMP/htdocs/richintime/ultimate-seed/node_modules/bcrypt
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok 
npm ERR! Darwin 13.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "bcrypt"
npm ERR! node v0.12.0
npm ERR! npm  v2.7.1
npm ERR! code ELIFECYCLE

npm ERR! bcrypt@0.7.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bcrypt@0.7.7 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
Run Code Online (Sandbox Code Playgroud)

Pet*_*ons 171

简单的解决方案是从"bcrypt"npm模块切换到bycryptjsbcrypt-nodejs.它是完全相同的API,但纯JS,因此没有处理的本机附加组件.

npm install --save bcryptjs && npm uninstall --save bcrypt
Run Code Online (Sandbox Code Playgroud)

然后将您的require调用更改为"bcryptjs",但所有代码都可以保持不变.

从长远来看,我怀疑目前bcrypt还没有为节点v0.12.0做好准备,但如果没有,它最终会更新并准备就绪.

  • 2019 - 看起来不再支持 bcrypt-nodejs (6认同)
  • bcryptjs 对我有用。但 bcrypt-nodejs 不会。 (2认同)
  • 这是一个修复,而不是修复。如果您无法切换到 bcrypt 的节点版本,请安装 node-gyp (尝试 npm i bcrypt npde-gyp --force ),然后尝试 npm i 。它应该正确构建。 (2认同)
  • 我安装了 bcrypt-nodejs,尽管它已经被弃用,然后删除它并再次安装 bcrypt。像这样,我成功安装了 bcrypt 并且运行良好。 (2认同)

Har*_*shi 23

对于Windows安装以下模块

npm install -g node-gyp
npm install --g --production windows-build-tools
Run Code Online (Sandbox Code Playgroud)

然后尝试安装

npm install bcrypt
Run Code Online (Sandbox Code Playgroud)


use*_*560 9

在这个命令上:

npm install --g --production windows-build-tools
Run Code Online (Sandbox Code Playgroud)

您可能必须在Windows计算机上以管理员身份在Powershell中运行它.

您可以通过右键单击Powershell并选择"以管理员身份运行"来执行此操作


Aks*_*ain 8

升级到bcrypt@5.0.0

npm i bcrypt@5.0.0

我在这个较新版本的 bcrypt 上没有收到错误,旧版本给出了不同类型的错误,从无法安装 bcrypt 到打字稿类型错误


Sur*_*ari 7

接受的解决方案有效,但 bcryptjs 比 python 和 C++ 版本慢。

如果你仍然想要 bcrypt 而不是 bcryptjs,工作解决方案是下面的命令,但它们也可能有自己的问题。

?? npm install -g node-gyp
? npm install --g --production windows-build-tools
Run Code Online (Sandbox Code Playgroud)

在 Windows 中,第二个命令将尝试与 python 一起安装 Visual Studio,因此出现问题是因为 Visual Studio 安装需要很多时间。它还阻碍了python的安装。如果您忘记以管理员身份运行这些命令,那么它们将安装在 C:\Users\User.windows-build-tools 中,但仍然无法工作,因为 node 将在 C:\ 或 C:\Program Files 中搜索 python。因此,在某些情况下,这些命令可能会增加您的复杂性。

所以对你来说最好的主意是为所有用户手动安装 python。没有必要将 python 添加到环境路径中。

然后运行:

?? npm install -g node-gyp
Run Code Online (Sandbox Code Playgroud)

现在您已准备好安装 bcrypt:

npm install bcrypt
Run Code Online (Sandbox Code Playgroud)