node.bcrypt.js icon indicating copy to clipboard operation
node.bcrypt.js copied to clipboard

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

Open jellohouse opened this issue 6 years ago • 48 comments

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.

jellohouse avatar May 13 '20 21:05 jellohouse

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

jellohouse avatar May 14 '20 02:05 jellohouse

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

spicecoder avatar Sep 21 '20 06:09 spicecoder

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.

joy45689 avatar Oct 06 '20 08:10 joy45689

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

its works for me ubuntu 18.04

vishalims095 avatar Dec 25 '20 15:12 vishalims095

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!

lehathanh avatar Dec 27 '20 00:12 lehathanh

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

lusm554 avatar Jan 15 '21 04:01 lusm554

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

AITuring avatar Feb 21 '21 22:02 AITuring

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 avatar Feb 23 '21 22:02 Shishoo

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

recrsn avatar Feb 24 '21 01:02 recrsn

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

Shishoo avatar Feb 24 '21 12:02 Shishoo

What's the error while trying to rebuild?

Do you have an outer layer of package.json?

recrsn avatar Feb 24 '21 12:02 recrsn

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

Shishoo avatar Feb 24 '21 16:02 Shishoo

Below solved the issue:

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

manoharreddyporeddy avatar Mar 24 '21 08:03 manoharreddyporeddy

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

Thanks man! That helped solve the error.

sk8Guerra avatar May 14 '21 01:05 sk8Guerra

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 :)

XiaoyunWu6666 avatar Aug 19 '21 04:08 XiaoyunWu6666

not work me

jongomes avatar Nov 10 '21 18:11 jongomes

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

mgalvao2012 avatar Mar 23 '22 13:03 mgalvao2012

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

This solved the issue. Thanks a lot.

duttaANI avatar Apr 29 '22 19:04 duttaANI

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

Solved my issue

AhmedHajeyah avatar Apr 04 '23 23:04 AhmedHajeyah

sudo npm i --unsafe-permaprès cela, installez bcrypt

ça marche pour moi ubuntu 18.04

ça à aussi fonctionner pour moi et je suis sur Mac os

axel-lukongo avatar Jun 09 '23 16:06 axel-lukongo