DEV Community

Cover image for How to fix `Cannot find module 'bcrypt'` error?
relliv
relliv

Posted on

How to fix `Cannot find module 'bcrypt'` error?

If you are working with PNPM and getting this error there are many possible solutions (check this stackoverflow post) but many of them not compatible with PNPM. bcrypt has system based dependencies. First you need to install node-gyp package globally and this package is compatible with only stable version of node.

First try with pnpm approve-builds command. Sometimes PNPM excludes (especially if you are working on a monorepo propject) buildable packages and this may cause Cannot find module 'bcrypt' error.

There is one more possible solution: replacing bcrypt with bcryptjs. bcryptjs is more modern solution and supports TypeScript.

Just remove bcrypt and install bcryptjs. Then update imports. API is mostly same. You don't need to update function calls.

Have a nice time.

Top comments (2)

Collapse
 
othimar profile image
Pélé Oussoumanou

Thanks. Installing node-gyp solved the problem for me.

Collapse
 
dan_le_brown profile image
Brown

thanks!