Skip to content

Conversation

@dev-hari-prasad
Copy link

What?

Exclude dev-only dependencies from being traced into the .next/standalone output when using Turbopack, preventing large build-time tools (e.g. TypeScript) from being bundled into the runtime artifact.

Why?

When output: "standalone" is enabled with Turbopack, devDependencies are currently traced and copied into the standalone bundle, even though they are never required at runtime.
This leads to significantly larger standalone outputs (e.g. typescript ~20 MB) and unexpected Docker image bloat.

Webpack does not exhibit this behavior, so this is a Turbopack-specific issue.

How?

Treat packages declared as devDependencies as untraced externals during standalone output generation.

Update the server resolver logic to respect this distinction while keeping existing external resolution behavior unchanged.

This ensures only runtime-required dependencies are included in .next/standalone.

Fixes and closes #86981

Introduce a mechanism to mark certain dev-only packages as external but not traced for standalone output. Added a JSONC file listing these packages and updated the resolve logic to respect this list, preventing unnecessary inclusion of dev dependencies in the standalone bundle.
Replaces loading server-external-untraced-packages.jsonc with dynamically reading devDependencies from package.json to determine packages that should not be traced for standalone output. Removes the now-unnecessary JSONC file and adds a utility function to extract devDependencies.
@nextjs-bot nextjs-bot added the Turbopack Related to Turbopack with Next.js. label Dec 17, 2025
@nextjs-bot
Copy link
Collaborator

Allow CI Workflow Run

  • approve CI run for commit: 14bc6c8

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Turbopack Related to Turbopack with Next.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typescript(~20MB) present in build .next/standalone/node_modules when using standalone output

2 participants