kelektiv/node.bcrypt.js

bug: `bcrypt + pnpm + turborepo` fails with `Cannot find module '../lib/main'`

PiotrekPKP opened this issue · 6 comments

Installation with existing node_modules directory fails with Cannot find module '../lib/main'

Hello :)

I'm encountering an issue with the bcrypt package. I have a turborepo monorepo with an api package and other apps. The package depends on bcrypt. Every time I want to add a new dependency to any app/package I have to remove the root node_modules folder and only then can I install it - reinstallation / adding a new package causes the error below:

> pnpm install <anything>

...

node_modules/bcrypt: Running install script, failed in 43ms
node_modules/bcrypt install$ node-pre-gyp install --fallback-to-build
│ node:internal/modules/cjs/loader:1078
│   throw err;
│   ^
│ Error: Cannot find module '../lib/main'
│ Require stack:
│ - /Users/peter/Developer/dinnery/node_modules/bcrypt/node_modules/.bin/node-pre-gyp
│     at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
│     at Module._load (node:internal/modules/cjs/loader:920:27)
│     at Module.require (node:internal/modules/cjs/loader:1141:19)
│     at require (node:internal/modules/cjs/helpers:110:18)
│     at Object.<anonymous> (/Users/peter/Developer/dinnery/node_modules/bcrypt/node_modules/.bin/node-pre-gyp:4:1)
│     at Module._compile (node:internal/modules/cjs/loader:1254:14)
│     at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
│     at Module.load (node:internal/modules/cjs/loader:1117:32)
│     at Module._load (node:internal/modules/cjs/loader:958:12)
│     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
│   code: 'MODULE_NOT_FOUND',
│   requireStack: [
│     '/Users/peter/Developer/dinnery/node_modules/bcrypt/node_modules/.bin/node-pre-gyp'
│   ]
│ }
│ Node.js v18.16.0
└─ Failed in 44ms at /Users/peter/Developer/dinnery/node_modules/bcrypt

Indeed, the lib/main file does not exist.

I've been encountering the same issue with bcrypt + turborepo + pnpm for some time now and found no suitable solution so far. I am currently considering replacing bcrypt with an alternative library due to this persistent problem.

I've been encountering the same issue with bcrypt + turborepo + pnpm for some time now and found no suitable solution so far. I am currently considering replacing bcrypt with an alternative library due to this persistent problem.

May I know what alternative library you're using?

I've been encountering the same issue with bcrypt + turborepo + pnpm for some time now and found no suitable solution so far. I am currently considering replacing bcrypt with an alternative library due to this persistent problem.

May I know what alternative library you're using?

I’m considering to use crypto.pbkdf2. I’m not sure if there is a ready to use solution, so you might have to write your own function depending on the use case.

I've been encountering the same issue with bcrypt + turborepo + pnpm for some time now and found no suitable solution so far. I am currently considering replacing bcrypt with an alternative library due to this persistent problem.

May I know what alternative library you're using?

I’m considering to use crypto.pbkdf2. I’m not sure if there is a ready to use solution, so you might have to write your own function depending on the use case.

thanks! i wrote a small script that basically removes node_modules/bcrypt every time you install something but i'm getting really tired of it haha

recrsn commented

bcrypt does not work with bundlers; neither do any native libraries. They depend on shared libraries (lib/main/bcrypt.so in our case) in specified locations. If it cannot find, because your tool plays around with node_modules location, it fails

@asobirov adding public-hoist-pattern[]=*bcrypt* works!!!