Next.js Discord

Discord Forum

Error: Cannot find module 'fs'

Answered
Bengal posted this in #help-forum
Open in Discord
BengalOP
So this only happened after I installed bcrypt. This is my first time using bcrypt and I'm also not using NextAuth due to project requirements. I read about the serverComponentsExternalPackages page but it seems bcrypt is already added.

I have a database.ts file where all of my functions are exported from. It has the "use server" line at the top. I have a very simple hash function:

async function hashPassword(password: string): Promise<string> {
    const hashedPassword = await bcrypt.hash(password, 10);
    return hashedPassword;
}


Which gets called inside another function, which is being used as a server action function. I assume that is the reason?

18 Replies

BengalOP
This is still in my local environment and to my knowledge I haven't enabled anything related to the edge?

Oh but I running it with the --turbo flag
Running without the turbo flag leads to a different error related to ./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
what does normal non turbo do? (sometimes i have gotten better error messages)
BengalOP
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!doctype html>
| <html>
| <head>

Import trace for requested module:
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
./lib/database.ts
 âš  ./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js
Module not found: Can't resolve 'npm' in '/Users/robin/Documents/Kuiper/node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util'

Import trace for requested module:
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
./lib/database.ts

./node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
./lib/database.ts
 âš  ./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js
Module not found: Can't resolve 'npm' in '/Users/robin/Documents/Kuiper/node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util'

Import trace for requested module:
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/.pnpm/@mapbox+node-pre-gyp@1.0.11/node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
./lib/database.ts

./node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
./lib/database.ts
Definitely a bigger pointing finger at bcrypt with this one
and you have installed this package... hmmm
BengalOP
multiple times, even tried npm instead of pnpm
TBH, I'm not restricted to bcrypt. I'm willing to switch as log as the result is achieved for me. This is a very minor part of the project for now
Answer
BengalOP
Will do, let me grab some cereal real quick 😂
I was not aware of the fact that bcrypt was a native module
nice
my weird googling worked 🙂
BengalOP
I was only looking at the next.js repo and didn't even thinkn to look over at bcrypts
Thanks a lot, you saved me a bunch of time
:prayge: