Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: bcrypt_lib.node is not a valid Win32 application

I have a nodejs project on my windows machine. Where upon attempting to run the project this error appears involving bcrypt and win32.

[nodemon] 2.0.2 [nodemon] to restart at any time, enter rs [nodemon] watching dir(s): . [nodemon] watching extensions: js,mjs,json [nodemon] starting node app.js internal/modules/cjs/loader.js:1003 return process.dlopen(module, path.toNamespacedPath(filename)); ^

Error: \\?\C:\Users\owner\desktop\msci444\no-scraps\node_modules\bcrypt\lib\binding\napi-v3\bcrypt_lib.node is not a valid Win32 application.
\\?\C:\Users\owner\desktop\msci444\no-scraps\node_modules\bcrypt\lib\binding\napi-v3\bcrypt_lib.node
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1003:18)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (C:\Users\owner\desktop\msci444\no-scraps\node_modules\bcrypt\bcrypt.js:6:16)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
[nodemon] app crashed - waiting for file changes before starting...

pt

like image 489
Mayyar Al-Atari Avatar asked Apr 01 '20 01:04

Mayyar Al-Atari


3 Answers

There are different possibilities how to resolve:

  • npm rebuild bcrypt --build-from-source (as stated in the comments already) check that your node version for recompiling matches the test/production version
  • npm install node-pre-gyp -g then npm rebuild bcrypt --build-from-source
  • Delete the folder containing npm-bcrypt on the deployment server inside your project folder node_modules (..programs\server\node_modules). On the deployment server, run npm install bcrypt

Hope one helpsyou

like image 69
Codebreaker007 Avatar answered Oct 31 '22 19:10

Codebreaker007


I was getting this error in my windows environment: previously I was running the project under windows subsystem linux, and once I needed to debug it in visual studio code, the environment started the windows version of node, which in turn was wondering about non win32 binaries of bcrypt library.

Removing the node_modules and then reinstalling them npm i solved the issue.

like image 10
arthur Avatar answered Oct 31 '22 19:10

arthur


I was experiencing the same problem. I was able to run my project changing my code in the following way:

From: //import * as bcrypt from 'bcrypt';

To: //import * as bcrypt from 'bcryptjs;

and installing dependencies: npm i bcryptjs --save

like image 1
Giovani Avatar answered Oct 31 '22 19:10

Giovani