Open Kavian77 opened 1 month ago
This would also help with https://github.com/vercel/next.js/discussions/46722#discussioncomment-10983611
this would be the preferred behaviour: Support custom servers natively in the standalone build (i.e., correctly bundle custom servers along with the app).
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/determined-shaw-nz95jm
To Reproduce
Create a new Next.js application with a custom server, or use yours if you already have one.
Try to bundle the server using the following approaches:
Standalone Build:
While the build succeeds, it does not support custom servers properly, as mentioned in this existing discussion. As a result, the standalone build ignores the custom server, preventing full bundling.
ESBuild:
This approach fails with dependency handling issues. Please find the logs here: esbuild.log
Bun:
Similar to ESBuild, this fails with dependency handling issues. Here is the output log: bun.log
Here are some of the common errors you can find in the logs linked above:
Could not resolve: "react-dom/server.edge"
Could not resolve: "critters"
Could not resolve: "react-server-dom-turbopack/client.edge"
Could not resolve: "react-server-dom-webpack/client.edge"
Could not resolve: "react-server-dom-webpack/server.node"
Current vs. Expected behavior
Current Behavior:
Bundlers or Build Tools (e.g. ESBuild and Bun): Fail due to dependency resolution issues. Likely related to how Next.js handles or manifests its internal dependencies or experimental forks of libraries. Standalone build: Does not support bundling of custom servers and ignores them during the build process.
Expected Behavior:
The build system should either:
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure, Output (export/standalone)
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
Bundling the entire application, including custom servers, is essential for production environments, especially when optimizing deployment artifacts such as Docker images. Proper bundling would allow removing the
node_modules
folder, greatly reducing the image size.