-
Notifications
You must be signed in to change notification settings - Fork 28k
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
Support custom servers with minimal node modules #72966
Merged
gaojude
merged 1 commit into
vercel:canary
from
MJez29:support-standalone-custom-servers
Nov 19, 2024
Merged
Support custom servers with minimal node modules #72966
gaojude
merged 1 commit into
vercel:canary
from
MJez29:support-standalone-custom-servers
Nov 19, 2024
+33
−11
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d219312
to
000ca86
Compare
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Tests Passed |
gaojude
approved these changes
Nov 19, 2024
lubieowoce
pushed a commit
that referenced
this pull request
Nov 20, 2024
Loading
Loading status checks…
Reverts #72966
wyattjoh
pushed a commit
that referenced
this pull request
Nov 28, 2024
## Fixing a bug ### Related issues fixes #64031 ### Why is this change needed Per the Next.js [docs](https://nextjs.org/docs/pages/api-reference/next-config-js/output) > Next.js' production server is also traced for its needed files and output at .next/next-server.js.nft.json which can be leveraged in production. When I tried doing this my [custom server](https://nextjs.org/docs/pages/building-your-application/configuring/custom-server) would crash on startup because of this codepath https://github.com/vercel/next.js/blob/canary/packages/next/src/server/config.ts#L1022 My first attempt at fixing this involved changing ``` if (!process.env.__NEXT_PRIVATE_STANDALONE_CONFIG) { ``` to ``` if (phase === PHASE_PRODUCTION_SERVER) { ``` but this is not guaranteed to work because the next.config.js and it's required dependencies may not be present causing the server to use the default config The best solution is to mimic standalone mode as closely as possible ### What does this change do This change allows a custom server running in production with only required files to pass in a preloaded next config (most likely from `required-server-files.json`) This is very similar to how the [standalone server works](https://github.com/vercel/next.js/blob/bc49287063d6afd50a7361566b14f1ab6c26b136/packages/next/src/build/utils.ts#L2142) ### Testing I'd like to get an initial round of feedback from the next team before I dive into writing an integration test. I patched nextjs in my repo and this solution worked
wyattjoh
pushed a commit
that referenced
this pull request
Nov 28, 2024
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixing a bug
Related issues
fixes #64031
Why is this change needed
Per the Next.js docs
When I tried doing this my custom server would crash on startup because of this codepath
https://github.com/vercel/next.js/blob/canary/packages/next/src/server/config.ts#L1022
My first attempt at fixing this involved changing
to
but this is not guaranteed to work because the next.config.js and it's required dependencies may not be present causing the server to use the default config
The best solution is to mimic standalone mode as closely as possible
What does this change do
This change allows a custom server running in production with only required files to pass in a preloaded next config (most likely from
required-server-files.json
)This is very similar to how the standalone server works
Testing
I'd like to get an initial round of feedback from the next team before I dive into writing an integration test. I patched nextjs in my repo and this solution worked