【问题标题】:Error installing bcrypt with npm使用 npm 安装 bcrypt 时出错
【发布时间】:2015-06-01 22:23:53
【问题描述】:

我无法在我的机器上使用npm 安装bcrypt,因为我遇到了以下错误。我一直在解决这个问题,但运气不佳。您能否推荐任何诊断或解决问题的步骤,以便我可以成功运行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

【问题讨论】:

标签: node.js npm bcrypt


【解决方案1】:

这发生在我身上,因为我正在从 github 安装一个包,该包具有旧版本的 bcrypt 作为依赖项。我刚刚卸载了旧的 bcrypt 版本并安装了最新版本:

    npm uninstall bcrypt
    npm install bcrypt

然后,瞧。它奏效了。

【讨论】:

    【解决方案2】:

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

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

    ✔️ npm install -g node-gyp
    ❌ npm install --g --production windows-build-tools
    

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

    所以对您来说最好的办法是✔️为所有用户手动安装 python。不需要将python添加到环境路径中。

    然后运行:

    ✔️ npm install -g node-gyp
    

    现在您可以安装 bcrypt:

    npm install bcrypt
    

    【讨论】:

      【解决方案3】:

      对于 windows 安装以下模块:

      npm install -g node-gyp
      npm install --g --production windows-build-tools
      

      然后尝试安装:

      npm install bcrypt
      

      【讨论】:

      • 这家伙给出了完美的答案。其他东西已弃用。
      • 在所有这些事情之后,您还应该将python 可执行文件添加到您的环境变量PATH,以便安装程序找到它,似乎需要它才能正确执行安装.
      • 您可以通过右键单击 Powershell 并选择“以管理员身份运行”来执行此操作
      • 还要确保关闭任何其他终端(因为我默认不使用 Powershell),以便让windows-build-tools 完成安装。谢谢你的回答顺便说一句
      • 在 Windows 上以管理员身份运行
      【解决方案4】:

      我有节点版本 12.18.3 并通过运行 npm i bcrypt@3.0.6 修复了它

      【讨论】:

        【解决方案5】:

        简单的解决方案是从“bcrypt”npm 模块切换到bycryptjsbcrypt-nodejs。它是完全相同的 API,但纯 JS,因此无需处理原生插件。

        npm install --save bcryptjs && npm uninstall --save bcrypt
        

        然后将您的require 调用更改为“bcryptjs”,否则您的所有代码都可以保持不变。

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

        【讨论】:

        • 比 python 版本慢 2.7 倍
        • bcryptjs 为我工作。但是,bcrypt-nodejs 没有。
        • 2019 - bcrypt-nodejs 似乎不再受支持
        • 它是一个修复,而不是修复。如果您无法切换到 bcrypt 的节点版本,请安装 node-gyp(尝试 npm i bcrypt npde-gyp --force)然后尝试 npm i 。它应该正确构建。
        • 我安装了 bcrypt-nodejs 虽然它已经被弃用了,然后删除它并再次安装 bcrypt。像这样,我成功安装了 bcrypt,它运行良好。
        【解决方案6】:

        跑步

        sudo apt install build-essential
        

        安装在 Linux 上安装 bcrypt 所需的所有工具。 然后就可以运行了

        npm install
        

        【讨论】:

          【解决方案7】:

          升级到bcrypt@5.0.0

          npm i bcrypt@5.0.0

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

          【讨论】:

            【解决方案8】:

            我安装了 bcrypt-nodejs 虽然它已经被弃用了,然后删除它并再次安装 bcrypt。像这样,我成功安装了 bcrypt,它运行良好。

            yarn add bcrypt-nodejs
            yarn remove bcrypt-nodejs
            yarn add bcrypt 
            

            【讨论】:

              【解决方案9】:

              我通过运行以下命令设法解决了这个问题: sudo apt-get install -y build-essential python 然后yarn add bcrypt

              您可以在此处找到说明:

              https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions

              https://github.com/kelektiv/node.bcrypt.js

              【讨论】:

                【解决方案10】:

                如果以上任何一项都不起作用,请执行以下操作:

                npm install node-gyp
                

                之后访问官方python下载站点Official Python download link

                安装最新版本的python,一定要勾选add python to path

                安装后,做:

                npm --save install bcrypt
                

                【讨论】:

                  【解决方案11】:

                  错误原因: Node 可能无法在您的系统上找到 Python 路径

                  解决方案

                  步骤:1 以管理员身份运行命令提示符 第二步安装包

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

                  可能需要一些时间,请耐心等待

                  第 3 步现在安装

                  npm install node-gyp
                  

                  最后一步现在您可以开始了

                  npm install bcrypt
                  

                  【讨论】:

                    【解决方案12】:

                    我也遇到了同样的问题。以下命令帮助了我。

                    npm rebuild
                    

                    然后

                    npm install bcrypt
                    

                    【讨论】:

                      【解决方案13】:

                      如果您在 Windows 上以管理员身份运行 powershell 并使用这些命令。

                      npm install --g --production windows-build-tools
                      

                      然后使用 bcrypt 安装

                      npm install --save bcrypt
                      

                      【讨论】:

                        【解决方案14】:

                        我在服务器端(aws ubuntu 16.04)面临同样的问题。

                        我尝试多次删除sudo rm -rf node_module/bcrypt的node_module/bcrypt,并通过各种方式一次又一次地重新安装,但仍然面临同样的问题。

                        我用 nvm 检查了节点版本,它也显示稳定(v10.11.0)。

                        最后,我尝试了。

                        sudo npm cache clean -f
                        sudo npm install -g n
                        sudo n stable
                        

                        它对我有用。

                        【讨论】:

                        • 谢谢。我尝试了上述所有解决方案,但没有任何效果。 bcrypt 的官方文档也 node-gyp 只适用于稳定的节点版本。
                        【解决方案15】:

                        我刚刚运行了以下命令,然后尝试安装,它成功了:

                        npm install node-pre-gyp -g
                        

                        【讨论】:

                          【解决方案16】:

                          关于这个命令:

                          npm install --g --production windows-build-tools
                          

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

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

                          【讨论】:

                            【解决方案17】:

                            遇到了同样的问题。更新 npm 并重试(通常是 npm install -g npm)。它为我解决了这个问题。

                            【讨论】:

                              【解决方案18】:

                              在 Mac OS 上,Xcode 更新后,运行 sudo gcc 并接受 Xcode 的新许可证解决了这个问题!

                              【讨论】:

                                猜你喜欢
                                • 2016-12-03
                                • 1970-01-01
                                • 1970-01-01
                                • 2012-12-26
                                • 2021-08-24
                                • 2020-03-31
                                • 1970-01-01
                                • 1970-01-01
                                • 2014-02-17
                                相关资源
                                最近更新 更多