-
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
Next.js should not start on "bad ports" #55050
Comments
Isn't this what's happening already? You are showing the stack trace that Next.js is outputting. On the client, we don't want to expose more information than necessary. Currently, you should be seeing something like |
In this particular case, I think it would be justified to have Next.js warn users about running on certain ports that are certain to crash in production, otherwise the user has to debug an issue that's not even technical, but originates in an arbitrary constraint imposed by a dependency, which is itself an implementation detail. |
This isn't just an implementation detail of Next.js should probably just hard error as soon as you try to start with one of those ports since no one will be able to visit your web app. Do you want to create a PR? |
In production you wouldn't usually run the website on these unusual ports directly. Instead you'd have it run on localhost[:port], and then get Apache or nginx to proxy it. So in theory, it wouldn't necessarily be an issue, as visitors to the website would access it on the usual ports (80, 443). But since it appears to be a wider web standard that these ports shouldn't be accessed by web clients, it adds more weight to having Next.js refuse to serve on them. I am not familiar enough with the codebase to create a PR for warning users against starting Next.js on a "bad port". |
You could add a similar check to exit the next.js/packages/next/src/cli/next-start.ts Lines 53 to 63 in df76f66
Same for next.js/packages/next/src/cli/next-dev.ts Lines 254 to 257 in df76f66
|
👋 I opened a PR here for just the |
### Fixing a bug - [x] Related issues linked using `fixes #number` - [x] Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - [x] Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md Closes NEXT- Fixes #55050 Co-authored-by: Steven <[email protected]> Co-authored-by: Tim Neutkens <[email protected]>
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/stupefied-parm-nkr2wn
To Reproduce
npm run start
) on a "bad port" (as defined by the fetch standard, e.g.4045
).Current vs. Expected behavior
The demonstrative example showcases the loading of a "next/image" component .
It loads fine in development mode, but fails in production when running on a "bad port":
next start
will display a stacktrace like:The stacktrace explains what's going on:
undici
implementation offetch
.undici
throws an error.The result is a production deployment that should work fine, but none of the images load, because the optimizer crashes when attempting to fetch them.
Here's how the fetch standard defines a "bad port":
https://fetch.spec.whatwg.org/#bad-port
One possible solution could be to mirror Undici's list of "bad ports", and raise it as an issue when running Next.js in production.
Verify canary release
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Binaries: Node: 16.17.0 npm: 8.15.0 Yarn: 1.22.19 pnpm: 7.1.0 Relevant Packages: next: 13.4.20-canary.18 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Image optimization (next/image, next/legacy/image)
Additional context
No response
NEXT-1608
The text was updated successfully, but these errors were encountered: