node.js 使用 npm 安装 bcrypt 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29320201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error installing bcrypt with npm
提问by hawkharris
I'm unable to install bcryptusing npmon my machine because I encounter the following errors. I have been troubleshooting the issue without much luck. Can you recommend any steps to diagnose or fix the problem so I can run npm install bcryptsuccessfully?
我无法在我的机器上安装bcryptusing npm,因为我遇到以下错误。我一直在对这个问题进行故障排除,但运气不佳。您能否推荐任何诊断或修复问题的步骤,以便我可以npm install bcrypt成功运行?
Someones-Macbook:node_modules Cody$ npm install bcrypt
npm WARN package.json [email protected] No README data
|
> [email protected] 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! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
回答by Peter Lyons
The easy solution is just switch from the "bcrypt" npm module to bycryptjsor bcrypt-nodejs. It's the exact same API, but pure JS so no native add-ons to deal with.
简单的解决方案是从“bcrypt”npm 模块切换到bycryptjsor bcrypt-nodejs。它是完全相同的 API,但是是纯 JS,因此无需处理本机附加组件。
npm install --save bcryptjs && npm uninstall --save bcrypt
Then change your requirecalls to "bcryptjs", but all your code otherwise can be unchanged.
然后将您的require调用更改为“bcryptjs”,但您的所有代码都可以保持不变。
Long term, I suspect at the moment bcrypt may not be ready for node v0.12.0 yet, but if not it will eventually be updated and ready.
从长远来看,我怀疑目前 bcrypt 可能还没有为节点 v0.12.0 做好准备,但如果没有,它最终会被更新并准备好。
回答by Harshal_m_joshi
for windows install the following module
对于 Windows 安装以下模块
npm install -g node-gyp
npm install --g --production windows-build-tools
then try to install
然后尝试安装
npm install bcrypt
回答by user3049560
On this command:
在这个命令上:
npm install --g --production windows-build-tools
You may have to run this in Powershell as administrator on your Windows machine.
您可能必须在 Windows 计算机上以管理员身份在 Powershell 中运行它。
You do that by right-clicking on Powershell and select "Run As Administrator"
您可以通过右键单击 Powershell 并选择“以管理员身份运行”来执行此操作
回答by kjohnsonthecoder
I just ran the following then tried the install and it worked:
我只是运行以下然后尝试安装,它工作:
npm install node-pre-gyp -g
回答by Suresh Chaudhari
The accepted solution won't work in 2020, Because bcryptjs is deprecated and no longer maintained because js version was much slower than python and c++ version.
接受的解决方案在 2020 年将不起作用,因为 bcryptjs 已弃用且不再维护,因为 js 版本比 python 和 c++ 版本慢得多。
? npm install --save bcryptjs && npm uninstall --save bcrypt
Now actually working solution are command below, but they can also have problem.
现在实际工作的解决方案是下面的命令,但它们也可能有问题。
?? npm install -g node-gyp
? npm install --g --production windows-build-tools
In Windows the second command will try to install visual studio along with python and hence the problem arises. because we why would we want to install Visual studio and it take a lot of time. and it also hinders the installation of python. And if you forget to run those command as Administrator then they will get installed at C:\Users\User.windows-build-tools which further will not work because node will search for python in C:\ or C:\Program Files\ . Hence this commands in some case increase your complications.
在 Windows 中,第二个命令将尝试与 python 一起安装 Visual Studio,因此出现问题。因为我们为什么要安装 Visual Studio 并且需要很多时间。并且它也阻碍了python的安装。如果您忘记以管理员身份运行这些命令,那么它们将安装在 C:\Users\User.windows-build-tools 中,这将进一步不起作用,因为节点将在 C:\ 或 C:\Program Files\ 中搜索 python . 因此,此命令在某些情况下会增加您的复杂性。
So the best idea for you is to ??install python manually for All Users And It is not necessary to add python to environment path. And run only the first command i.e
所以对你来说最好的主意是为所有用户手动安装 python 并且没有必要将 python 添加到环境路径。并且只运行第一个命令即
?? npm install -g node-gyp
Now you are ready to install bcrypt
现在您已准备好安装 bcrypt
npm install bcrypt
回答by Adrien Joly
On Mac OS, after a Xcode update, running sudo gccand accepting Xcode's new license solved the problem!
在 Mac OS 上,在 Xcode 更新后,运行sudo gcc并接受 Xcode 的新许可证解决了问题!
回答by Jitendra
I was facing the same issue on the server side( aws ubuntu 16.04).
我在服务器端(aws ubuntu 16.04)面临同样的问题。
I tried deleting node_module/bcrypt by sudo rm -rf node_module/bcryptmultiple times and reinstalled it again and again by various ways but still facing the same issue.
我尝试多次删除 node_module/bcryptsudo rm -rf node_module/bcrypt并通过各种方式一次又一次地重新安装它,但仍然面临同样的问题。
I checked node version with nvm and it was also showing stable (v10.11.0).
我用 nvm 检查了节点版本,它也显示稳定(v10.11.0)。
Finally, I tried.
最后,我试过了。
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
and it worked for me.
它对我有用。
回答by Imran Hussain
If you are on windows run powershell as administrator and use these commands.
如果您在 Windows 上以管理员身份运行 powershell 并使用这些命令。
npm install --g --production windows-build-tools
and then install bcrypt using
然后使用安装 bcrypt
npm install --save bcrypt
回答by Shubham Dubey
I was also having the same problem. The following commands helped me.
我也遇到了同样的问题。以下命令帮助了我。
npm rebuild
then
然后
npm install bcrypt
回答by M Abdullah
Reason for Error: Node maybe can't able to find the Python path on your system
错误原因:节点可能无法在您的系统上找到 Python 路径
Solution
解决方案
step: 1Rum command prompt as administrator step 2Install the package
步骤: 1以管理员身份运行 Rum 命令提示符 步骤 2安装软件包
npm install --global --production windows-build-tools
It may take some while, keep patient
可能需要一段时间,请耐心等待
step 3Now install
第 3 步现在安装
npm install node-gyp
Last stepNow you are ready to Go
最后一步现在你准备好了
npm install bcrypt

