13

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

Codebreaker007
  • 2,911
  • 1
  • 10
  • 22
Mayyar Al-Atari
  • 199
  • 1
  • 1
  • 9
  • Hi, according to this response https://github.com/kelektiv/node.bcrypt.js/issues/635#issuecomment-464506366 you need to run => npm rebuild bcrypt --build-from-source – Oscar Velandia Apr 01 '20 at 01:24
  • Please update the question title with `bcrypt_lib.node is not a valid Win32 application` – Shahrukh A. Apr 01 '20 at 02:02

9 Answers9

26

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

Codebreaker007
  • 2,911
  • 1
  • 10
  • 22
12

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.

arthur
  • 1,034
  • 2
  • 17
  • 31
2

Remove or delete node_modules and reinstall all packages.

Syscall
  • 19,327
  • 10
  • 37
  • 52
Don Banks
  • 21
  • 2
2

This error occurs when you swap files from one operating system to another. Eg copy/move project files from MacOS to Windows or Linux. To fix it delete the node modules files and do a clean npm install

Kipruto
  • 721
  • 6
  • 16
1

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

Giovani
  • 175
  • 1
  • 7
1

Try these steps;

Step 1: Expand node_modules

Step : Delete bcrypt package

Step 3: Run npm install or yarn install

Step 4: Restart server

Lojith Vinsuka
  • 906
  • 1
  • 10
  • 8
  • 1
    thanks, I was struggling to run my server. By the way, how do you get this kind of solution? – Mahantesh. N. Hadimani. Jan 01 '23 at 07:50
  • @Mahantesh.N.Hadimani. I think npm packages that includes python files (there are python files inside bcrypt package) need to build using node-gyp or node-pre-gyp. In my case, I linked my project directory to a (linux) docker container and ran it inside docker (I think all node modules and bcrypt were built using linux version of node-gyp/node-pre-gyp). Then after ran it locally without using docker (without removing node modules) I got the error. Then I restart server locally after removing bcrypt and running yarn install. After that I didn't get the error :) – Lojith Vinsuka Jan 01 '23 at 09:00
1

I faced the same issue; I installed bcrypt using the WSL subsystem with npm i bcrypt which I assume installs an architecturally specific version which doesn't mesh with Windows. I had nodemon running on my local machine's terminal and when I tried running my app, it kept crashing.

So I deleted the node_modules folder and then used npm i on my local machine's terminal instead to install the packages and it worked without a hitch!

Aishwarya
  • 11
  • 1
0

I faced the same issue; I installed bcrypt using the WSL subsystem with npm i bcrypt which I assume installs an architecturally specific version which doesn't mesh with Windows. I had nodemon running on my local machine's terminal and when I tried running my app, it kept crashing.

So I deleted the node_modules folder and then used npm i on my local machine's terminal instead to install the packages and it worked without a hitch!

(I have nodemon on my local machine because supposedly mongod doesn't work well with WSL)

DeviousLab
  • 17
  • 6
0

Ensure to add node path to environments. for me in WHM server:

export PATH=$PATH:/opt/cpanel/ea-nodejs10/bin/
alirezacode
  • 116
  • 4