node.js 找不到模块“bcrypt”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34546272/
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
Cannot find module 'bcrypt'
提问by Ramesh Chand
I am getting error Cannot find module 'bcrypt' in nodejs application
我收到错误在 nodejs 应用程序中找不到模块“bcrypt”
I have tried to install it using npm install bcryptbut still getting the issue.
我尝试使用npm install bcrypt安装它, 但仍然遇到问题。
node app.js
Error message:
错误信息:
Dec 30 2015 5:22:18 PM+05:30 - info: Connected to database:
postgres://testdb:see2@$W@localhost/testdb
Dec 30 2015 5:22:18 PM+05:30 - error: Error: Cannot find module 'bcrypt'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (D:\...\server\modules\user\model
s\user.js:11:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
回答by Tyler Collier
The solution for me was to npm rebuild.
我的解决方案是npm rebuild.
回答by Ramesh Chand
Using npm install bcryptcommand can't resolve the issue for me.
使用npm install bcrypt命令无法为我解决问题。
I tried the commands below and my issue resolved.
我尝试了以下命令并解决了我的问题。
npm install node-gyp -g
npm install bcrypt -g
npm install bcrypt --save
回答by maaroufi mohamed amine
use bcryptjsinstead bcrypt this is worked for me
使用bcryptjs而不是 bcrypt 这对我有用
npm install bcryptjs --save
回答by leompeters
回答by Abhu
Solution 1: lengthy method is : Install all dependencies first.
解决方案1:冗长的方法是:首先安装所有依赖项。
npm install -g windows-build-tools, npm install -g node-gyp
npm install -g windows-build-tools, npm install -g node-gyp
then, install bcrypt : npm install bcrypt
然后,安装 bcrypt :npm install bcrypt
Solution 2: easy method. No dependencies installation required.
解决方案2:简单的方法。无需安装依赖项。
npm install bcryptjs
npm 安装 bcryptjs
...You might have installed bcrypt but it seems like the installation was not successful for some reason. check the package.json file. If you cannot find bcrypt, the installtion was unsuccessful. You have to install again.
...您可能已经安装了 bcrypt,但由于某种原因,安装似乎没有成功。检查 package.json 文件。如果找不到 bcrypt,则安装失败。您必须重新安装。
As everyone explained, it because of lack dependencies that your installation was unsuccessful. You can checkout the required dependencies in the link: https://www.npmjs.com/package/bcrypt
正如每个人所解释的,由于缺乏依赖项,您的安装不成功。您可以在链接中查看所需的依赖项:https: //www.npmjs.com/package/bcrypt
Note: To use bcrypt: var bcrypt = require('bcrypt');.....
注意:要使用 bcrypt: var bcrypt = require('bcrypt'); .....
to use bcryptjs. var bcrypt = require('bcryptjs');
使用 bcryptjs。 var bcrypt = require('bcryptjs');
for reference: https://www.npmjs.com/package/bcrypthttps://www.npmjs.com/package/bcryptjs
供参考:https: //www.npmjs.com/package/bcrypt https://www.npmjs.com/package/bcryptjs
回答by Dholu
This worked for me.
这对我有用。
1) Delete any bcryptfolder in nodemodulesfolder, folder may have been created due to your repeated tries.
(C:\Program Files\nodejs\node_modules\npm\node_modules)
1) 删除bcrypt文件夹中的任何文件nodemodules夹,由于您反复尝试,文件夹可能已经创建。( C:\Program Files\nodejs\node_modules\npm\node_modules)
2) run this code npm install --save bcryptjse.g -
2)运行此代码,npm install --save bcryptjs例如 -
C:\Projects\loginapp>npm install --save bcryptjs
回答by Krishna Mohan
Before using npm install, change the package.jsonfile dependencies, i.e.
使用前npm install,更改package.json文件依赖,即
"bcrypt":"0.7.6"
to
到
"bcrypt":"*"
回答by thepanuto
In my case, npm rebuildalone didn't solved it. I also had to:
在我的情况下,npm rebuild单独没有解决它。我还必须:
$ npm install -g node-gyp
$ sudo apt-get update
$ sudo apt-get install build-essential
$ npm rebuild
npm rebuildwas trying to run make.
npm rebuild正试图跑make。
回答by Radisav Savkovic
If none of these examples didn't work, you should try to downgrade Node version installed:
如果这些示例都不起作用,您应该尝试降级安装的 Node 版本:
E.g from Node version 10 to version 9
例如,从 Node 版本 10 到版本 9
npm install node@<version of node>
回答by Andreas Bigger
It seems that bcrypt was depreciated at version 1.0.3 as it was susceptible to a wrap-around bug. NPM recommends installing version 2.0.0.
似乎 bcrypt 在 1.0.3 版中贬值了,因为它容易受到环绕错误的影响。NPM 建议安装 2.0.0 版。
So, if you wish to save it, just run the command:
所以,如果你想保存它,只需运行命令:
npm install [email protected] --save

