-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails in Next.js app/ directory incl. with API Route Handlers #979
Comments
Reading this issue in the So it occurred to me that maybe I should be using an
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
+ webpack: (config) => {
+ config.externals = [...config.externals, 'bcrypt'];
+ return config;
+ },
};
module.exports = nextConfig; Which indeed works (does not work on StackBlitz because the native module does run there): CodeSandbox demo: https://codesandbox.io/p/sandbox/gracious-bose-wn2731?file=%2Fnext.config.js |
Closing this out here and continuing the discussion over in the Next.js repo: |
I tried that, I got this error: ./node_modules/next-auth/core/init.js (10:14)
Module not found: Can't resolve 'crypto'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/next-auth/core/index.js
./node_modules/next-auth/next/index.js
./node_modules/next-auth/index.js
./app/api/auth/[...nextauth]/route.ts |
I had the same problem. The problem was solved by installing and importing. Instead of bcrypt install bcryptjs.
|
I'm integrating authentication with nextauth v5 in nextjs 14.0.4 with prisma and I just got the error, I don't know, but bcryptjs worked instead of bcrypt |
I'm a little scared to install bcryptjs because its last publication was 7 years ago and there are at least 40 issues open |
This error happens when you run bcrypt on the client side, to correct it if you don't want to use it on the client side but the error is still returning, check that all the places where you are using bctypt have "use server" |
Issue is still not resolved with Next.js 14.0. Still getting the error while using Client component |
Same error with argon2. I'm looking for a workaround |
thank you it worked |
I'm on the same boat... got error with argon2 |
Finally got around the issue. Here's how you can fix this: First, in next.config.js push bcrypt to config.externals like so:
Then where ever you are using bcrypt, instead of importing it in the traditional way (import bcrypt from 'bcrypt') You need to import it like so:
And make sure to put it above the line where it's being used. For example,
|
@umair-mirza Thanks brother. |
Thanks @umair-mirza .. great man |
@umair-mirza 🙏🏻 |
Could you let me know if you were able to get this resolved? |
Hello. i'm encountering this problem in next js 14 middleware. Any solution? |
For me the solution was to use: |
You will not get custom event handlers etc this way, also you are importing client side only code and @/auth means your custom auth implementation which you changed to one delivered with the next-auth package - if this solves your particular case, then fine - but I would advise against it in most cases as the problem within this thread is that it doesn't work on server side components |
Tried all solution. The one using |
Still have the same issue for bcrypt, argon2, @node-rs/bcrypt and @node-rs/argon2 on Next.js 14.2.3. Set the serverComponentExternalPackages for all 4 of these packages and the Webpack configuration but still no solution. Had to use bcryptjs for now. |
I replaced bcrypt with bcryptjs, and everything works okay. Running with:
|
Me too. Used bcryptjs and works well but super slow. |
Instead of using bcrypt, we should use bcryptjs.
|
Hey guys this is a known issue with bcrypt, bcrypt is a native module and when nextjs tries to import it in the client side, this error happens, a simple fix is to make the file where you are importing and using bcrypt to be a server file, add the |
After several attempts, I managed to get bcrypt working with auth.js v5.0.0-beta.17. The key lies in performing the The auth.ts file must be with the {...authConfig + providers}, this way it works 100% with bcrypt. Example: https://github.com/ezeparziale/quark/blob/main/src/auth.ts |
works for @node-rs/argon2 as well. add it to dependencies, install and import using require syntax |
Use it. custom by crypto module
|
For me problem solved: 'use server' instead of 'use client' in a component. |
Thanks, this helped me out! Scenario: I moved my function that uses bycript to a utilities file that had both client and server functions. Even though I only ever called it on the server, it still produced the error during the build. Fix: I moved all server utility functions to their own file under the |
Sadly I have an error which say "bcrypt is not defined" this way, has anyone else encountered this issue?" |
Looks like the issue occurs if you have a middleware that indirectly references bcrypt (even though the middleware should be running on the server). |
but what if I use the nextjs 15 rc with the turbo compiler, how can I config and use the bcrypt as the external dependencies? with the similar config here below? webpack: (config) => {
config.externals = [...config.externals, "bcrypt"];
return config;
}, |
in my case this issue was resolved putting
|
My workaround for the issue with |
What went wrong?
Using
bcrypt
within a Route Handler in Next.js (API Route Handler within the newapp/
directory) causes the app to crash with unusual errors:I also reported over here in the Next.js repo:
What did you expect to happen?
bcrypt
should work in theapp/
directory, including in Route HandlersWhich version of nodejs and OS?
If you find a bug, please write a failing test.
Ok, maybe once I find out more.
The text was updated successfully, but these errors were encountered: