fs module missing using bcrypt
Unanswered
<Milind ツ /> posted this in #help-forum

Hi, I have been trying to use bcrypt in my nextjs project that uses the pages router. On installing bcrypt and calling the
sample code:
however, if i remove these lines of code and refresh the web page, page loads fine. I do not have fs installed in dependency but on installing fs, it makes no difference.
bcrypt.hash()
to create a hash password, it throws me Import trace for requested module:
./node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/bcrypt/bcrypt.js
./pages/todoify/resetPass.tsx
- wait compiling...
- error ./node_modules/@mapbox/node-pre-gyp/lib/clean.js:8:0
Module not found: Can't resolve 'fs'
https://nextjs.org/docs/messages/module-not-found
sample code:
const salt = bcrypt.genSaltSync(10);
const hashedPass = bcrypt.hashSync(pass, salt);
however, if i remove these lines of code and refresh the web page, page loads fine. I do not have fs installed in dependency but on installing fs, it makes no difference.
19 Replies

things i have tried till now:
- updated node to latest version
- restarted windows
- removed node_modules and .next folder and did
- updated node to latest version
- restarted windows
- removed node_modules and .next folder and did
npm i

Northeast Congo Lion
any updates?

Oh yea, so turns out bcrypt does not work on the browser. We have to either use bcryptjs or use bcrypt on server/api routes
Tried the api route way and it worked
Tho i came across another issue later on.
I am working on a flutter app that uses realmdb so for login purposes, when we use bcrypt on flutter side as well to hash the password, it always generates random hashes.
Any trick you know for this?
I am working on a flutter app that uses realmdb so for login purposes, when we use bcrypt on flutter side as well to hash the password, it always generates random hashes.
Any trick you know for this?

@<Milind ツ /> Tho i came across another issue later on.
I am working on a flutter app that uses realmdb so for login purposes, when we use bcrypt on flutter side as well to hash the password, it always generates random hashes.
Any trick you know for this?

Why do you want to hash the password client-side?

I know I shouldn't but I am not a backend developer. Plus I can't seem to be able to configure how the login methods works on realm app services

It's not that you shouldn't, but I don't know why you would. It's usually the server's job.
Idk Realm but from what I can see, it expects the password as plain text, doesn't it?
Idk Realm but from what I can see, it expects the password as plain text, doesn't it?

Yes, the default mechanism of email/pass provider they offer used plain email and passwords.
They do offer an option to create a custom function that handles the user creation.
They do offer an option to create a custom function that handles the user creation.
But that doesn't work properly on flutter SDK.

And which one are you using?

The default mechanism
App isn't live yet so plain passwords it is

Realm most likely hashes the passwords themselves. If they wouldn't they would be dumb so don't worry.

Would still need to confirm they do or not

I would bet both of my hands that they do. If they wouldn't do it, they would risk a big and unnecessary law suit which they could have prevented with 2 additional lines of code.
Every company does and big companies that offer authentication services usually know what they are doing and have people in place whose only job it is to check if the data is secure

Ah, then it's safe to proceed without bcrypt

Yes