Skip to content
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
merged 1 commit into from
Nov 19, 2024

Conversation

MJez29
Copy link
Contributor

@MJez29 MJez29 commented Nov 19, 2024

Fixing a bug

Related issues

fixes #64031

Why is this change needed

Per the Next.js docs

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 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

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

@ijjk ijjk added Documentation Related to Next.js' official documentation. type: next labels Nov 19, 2024
@MJez29 MJez29 force-pushed the support-standalone-custom-servers branch from d219312 to 000ca86 Compare November 19, 2024 18:03
@ijjk
Copy link
Member

ijjk commented Nov 19, 2024

Allow CI Workflow Run

  • approve CI run for commit: 000ca86

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Sorry, something went wrong.

@ijjk
Copy link
Member

ijjk commented Nov 19, 2024

Tests Passed

@gaojude gaojude self-requested a review November 19, 2024 19:12
@gaojude gaojude merged commit 1bf0266 into vercel:canary Nov 19, 2024
105 of 106 checks passed
gaojude added a commit that referenced this pull request Nov 20, 2024
lubieowoce pushed a commit that referenced this pull request Nov 20, 2024
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
@github-actions github-actions bot added the locked label Dec 4, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Related to Next.js' official documentation. locked type: next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing webpack dependency when using output standalone + custom server
3 participants