27

I'm trying to start a nodeJS application, but I do get the error

Error: The module '/Users/api/node_modules/bcrypt/lib/binding/bcrypt_lib.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 46. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

I already run npm install and npm rebuild. But still the same error...

user3142695
  • 15,844
  • 47
  • 176
  • 332

1 Answers1

45

The bcrypt package needs to be rebuild, because it was initially installed with another version of Node.js.

Try this:

npm rebuild bcrypt --update-binary

for yarn users:

yarn add bcrypt --force
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • 10
    Tried this, didn't work. Still having warn `NODE_MODULE_VERSION 48. This version of Node.js requires NODE_MODULE_VERSION 57` – spaceman Feb 08 '18 at 19:10
  • 2
    @spaceman try reinstalling `bcrypt` in that case (or first uninstall, then install again). – robertklep Feb 10 '18 at 12:53
  • @robertklep How to reinstall `bcrypt`? Doing `npm install bcrypt --save` does not help. – Suhail Gupta Jun 12 '18 at 07:07
  • @SuhailGupta you have to be more specific, or perhaps even create a new question about the specific problem you're having. – robertklep Jun 12 '18 at 08:44
  • 1
    If you use node nightly, it's not enough to copy the `node` binary to `/usr/local/bin/node`, but you need also to copy `lib/node_modules` and `include/node` to `/usr/local/lib/node_modules` and `/usr/local/include/node` respectively, where later is most important as its sets the new NODE_MODULE_VERSION when you build packages locally. After copying the files, make sure to wipe your node_modules from your project and reinstall _everything_. – Marc J. Schmidt Apr 18 '19 at 16:31
  • Great working for me this solution. – Ravindra Singh Jun 05 '19 at 16:03
  • If this fails, you can always do (the classic) `rm -f /node_modules && rm -f package-lock.json && npm i`. Bit of a sledgehammer to crack a nut, but it works. – Reece Daniels Jan 23 '20 at 09:56
  • I tried everything for this problem, completely wiping my node_modules and reinstalling, running `npm rebuild` multiple times, changing Node versions. Nothing worked, until I ran `npm rebuild my_module_name --update-binary`. So glad I found this answer! – Kevin Lamping Nov 28 '20 at 19:22