Node.bcrypt.js: Error: Cannot find module '...../bcrypt/lib/binding/napi-v3/bcrypt_lib.node'

Created on 13 May 2020  路  14Comments  路  Source: kelektiv/node.bcrypt.js

After installing the newest version of node 12.6.3 and installing bcrypt 4.0.1 in my project,
"npm install bcrypt" added the package successfully without errors, but then running "node app.js" I get:

Error: Cannot find module 'path_to_my_project/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node'

And indeed the folder node_modules/bcrypt/lib is not there at all...

Why would installation not make this folder?
I suspect it's something to do with node-gyp not doing it's thing, but why don't I get an error message when i do npm install?

And I tried reverting to my old node version 8.11.1 using https://www.npmjs.com/package/n to manage my node versions and then installing bcrypt 2.0.1 (like I had previously), but it's behaving the exact same way... npm install adds the package but the bcrypt/lib folder is missing.
I also tried with node 12.6.1 and 12.6.2, same thing.

Most helpful comment

Ok for anyone else having this issue here is how I solved it, I had to compile it manually for some reason:
cd node_modules/bcrypt
node-pre-gyp install --fallback-to-build

All 14 comments

Ok for anyone else having this issue here is how I solved it, I had to compile it manually for some reason:
cd node_modules/bcrypt
node-pre-gyp install --fallback-to-build

node-pre-gyp install --fallback-to-build.. solved my issue too thanks

Ok for anyone else having this issue here is how I solved it, I had to compile it manually for some reason:
cd node_modules/bcrypt
node-pre-gyp install --fallback-to-build

It solves my problem too. Thanks.

sudo npm i --unsafe-perm
after that install bcrypt

its works for me ubuntu 18.04

Ok for anyone else having this issue here is how I solved it, I had to compile it manually for some reason:
cd node_modules/bcrypt
node-pre-gyp install --fallback-to-build

This works for me on newly installation on Windows 10/VSC, nodeJS v14.15.1. Thanks a lot!

Ok for anyone else having this issue here is how I solved it, I had to compile it manually for some reason:
cd node_modules/bcrypt
node-pre-gyp install --fallback-to-build

It helps me. Thanks

if mac still have problems after node-pre-gyp install --fallback-to-build, maybe it's mac problem. You should fix xcun.

node version: 14.16.0 (LTS)
npm version: 6.14.11
bcrypt: [email protected]
OS: Windows 10

I get the following error:

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '...path...\node_modules\bcrypt\lib\binding\napi-v3\bcrypt_lib.node'
Require stack:
- ...path...\node_modules\bcrypt\bcrypt.js
- ...path...\crypto.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (...path...\node_modules\bcrypt\bcrypt.js:6:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '...path...\\node_modules\\bcrypt\\bcrypt.js',
    '...path...\\crypto.js'
  ]
}

I have tried the fixes here and here and haven't been able to resolve the issue.

@Shishoo it appears that your bcrypt DLL is missing. Run npm rebuild bcrypt

@recrsn
Hi Amitosh - with reference to your previous post here on 27/12/2017, I did try
npm rebuild bcrypt - unfortunately this didn't work.

What's the error while trying to rebuild?

Do you have an outer layer of package.json?

@recrsn

There is NO error when I run npm rebuild bcrypt

Here is everything I have encountered and contained within the project directory:

----------------------------------------------------
> npm i bcrypt
----------------------------------------------------

npm WARN deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

+ [email protected]
added 68 packages from 116 contributors and audited 68 packages in 13.075s

1 package is looking for funding
  run `npm fund` for details    

found 0 vulnerabilities

--------------------------------------------------
> node app.js
----------------------------------------------------

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'F:\...path-to-file\node_modules\bcrypt\lib\binding\napi-v3\bcrypt_lib.node'
Require stack:
- F:\...path-to-file\bcrypto\node_modules\bcrypt\bcrypt.js
- F:\...path-to-file\bcrypto\app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (F:\...path-to-file\node_modules\bcrypt\bcrypt.js:6:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'F:\\...path-to-file\\node_modules\\bcrypt\\bcrypt.js',
    'F:\\...path-to-file\\bcrypto\\app.js'
  ]
}

----------------------------------------------------
> npm rebuild bcrypt
----------------------------------------------------

[email protected] F:\...path-to-file\bcrypto\node_modules\bcrypt

**(No errors or warnings)**

----------------------------------------------------
> node app.js
----------------------------------------------------

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'F:\...path-to-file\node_modules\bcrypt\lib\binding\napi-v3\bcrypt_lib.node'
Require stack:
- F:\...path-to-file\bcrypto\node_modules\bcrypt\bcrypt.js
- F:\...path-to-file\bcrypto\app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (F:\...path-to-file\node_modules\bcrypt\bcrypt.js:6:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'F:\\...path-to-file\\node_modules\\bcrypt\\bcrypt.js',
    'F:\\...path-to-file\\bcrypto\\app.js'
  ]
}

----------------------------------------------------
contents of: package.json
----------------------------------------------------

{
  "name": "bcrypto",
  "version": "1.0.0",
  "description": "testing bcrypt",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^5.0.0"
  }
}

----------------------------------------------------
contents of: app.js
----------------------------------------------------

// REF: https://www.npmjs.com/package/bcrypt
const bcrypt = require('bcrypt');

pwd = '拢MonkeyMa9ic';

const hashPassword = async (pwd) => {
  const salt = await bcrypt.genSalt(11);
  const hash = await bcrypt.hash(pwd, salt)

  console.log(salt);
  console.log(hash);
};

Below solved the issue:

  1. // delete node_modules / rename node_modules to something else
  2. npm cache clean --force
  3. npm i

@Shishoo it appears that your bcrypt DLL is missing. Run npm rebuild bcrypt

Thanks man! That helped solve the error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

japita-se picture japita-se  路  4Comments

summertong picture summertong  路  5Comments

potts99 picture potts99  路  5Comments

Z3roCoder picture Z3roCoder  路  5Comments

raj9211 picture raj9211  路  3Comments