kelektiv / node.bcrypt.js

bcrypt for NodeJs
MIT License
7.38k stars 510 forks source link

fs module missing error in nextjs #1008

Closed milindgoel15 closed 8 months ago

milindgoel15 commented 8 months ago
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/test.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 nextjs page code:

code ```tsx import React from "react"; import bcrypt from "bcrypt"; let Test = () => { const salt = bcrypt.genSaltSync(10); return ( <>

hello world

); }; export default Test; ```
recrsn commented 8 months ago

bcrypt is a native module and does not work in the browser. Use bcryptjs instead

It will work on server components with "use server" but you will need to disable bundling it.