-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Route Handlers Crash with bcrypt #46493
Comments
It seems is not only inside of Route Handlers it seems to be in any place inside of app directory. if for example i try to hash something in a server component the error is going to trigger too. This problem is not new and has been there since to be there since the release of Next.js 13 https://stackblitz.com/edit/vercel-next-js-hhp1ck?file=app%2Flayout.tsx,app%2Fpage.tsx |
Also reported in |
WorkaroundReading 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 cc @sokra is this a good solution here? |
It's not really a solution for the initial problem but have you tried using Pufferfish2 instead of bcrypt? |
Not a bug, this is documented here: https://beta.nextjs.org/docs/api-reference/next.config.js#servercomponentsexternalpackages You could add |
Thanks for the answer @balazsorban44 🙌
Ah nice, wasn't aware of these details, cool 👍 WorkaroundSo another (more official) workaround is something like this:
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
+ serverComponentsExternalPackages: ['bcrypt'],
},
};
module.exports = nextConfig;
Thanks for that, yeah maybe the name needs to change to |
I noticed that in the
Maybe |
Yeah feel free to add bcrypt 👍 |
omw 😉 |
just added bcrypt to the list, only gotta do a test-run and such then I'll push it into a PR 👍 |
…#46532) fixes #46493 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Thanks for the PR, review and merge @JesseKoldewijn and @timneutkens ! Looking forward to seeing this in |
Confirmed that versions starting at CodeSandbox: https://codesandbox.io/p/sandbox/gifted-bhaskara-w37l3k?file=%2Fnext.config.js |
this fixes the same as #46493 but for [argon2](https://www.npmjs.com/package/argon2) <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: --> ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [x] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Middleware / Edge (API routes, runtime)
Link to the code that reproduces this issue
https://stackblitz.com/edit/vercel-next-js-tteixg?file=app%2Fpage.tsx
To Reproduce
api/route.ts
and cause the server crashDescribe the Bug
When importing
bcrypt
in a Route Handler and compiling that route, the process crashes, being unable to parse the HTML:If this issue is avoided using an
html-loader
or similar, then further errors appear, about missingmock-aws-s3
,aws-sdk
, andnock
modules:If you install those modules, you get a bunch of critical dependency warnings and other errors like
Error: /home/projects/vercel-next-js-cc6lum/.next/server/app/api/package.json does not exist
Expected Behavior
Using
bcrypt
within an API Route Handler should work.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: