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

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.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 26

Most upvoted 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

Below solved the issue:

  1. // delete node_modules , or 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

I fixed this issue this way. On the terminal from root folder of the project: cd node_modules/bcrypt make

@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.

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

It solves my problem too. Thanks.

I was missing node-gyp on my system, after installing it and rebuilding like told by @recrsn npm rebuild bcrypt this solved my issue

I fixed this issue this way. On the terminal from root folder of the project: cd node_modules/bcrypt make

Solved my issue

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

The only answer online that eventually helped me 😃

@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 node-pre-gyp@0.15.0: 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 bcrypto@1.0.0 No description
npm WARN bcrypto@1.0.0 No repository field.

+ bcrypt@5.0.0
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
----------------------------------------------------

bcrypt@5.0.0 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);
};

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

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!

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