Skip to content

Next.js standalone bloat: instrumentation uses process.cwd() for buildDir resolution #180

@an2n

Description

@an2n

When using standalone together with turbopack, importing and running
@fortedigital/nextjs-cache-handler/instrumentation can make the standalone output huge
(it starts including many project/repo files).

During next build --turbo, process.cwd() is the project root. With output: "standalone" enabled,
Next.js output tracing can then pull in far more files than needed into the standalone output.

The tracer performs static analysis to determine which files need to be included in the standalone output. When it encounters path.join(process.cwd(), <dynamic_variable>), it cannot determine what path will be accessed at runtime and therefor includes the project root to ensure no files are missing at runtime.

Versions

  • Next.js: 15.5.9
  • @fortedigital/nextjs-cache-handler: 2.3.2

Reproduction

  1. Configure Next.js with output: "standalone".
  2. Import and call registerInitialCache from @fortedigital/nextjs-cache-handler/instrumentation.
  3. Run next build --turbo.
  4. Inspect .next/standalone and see many unrelated repo files included.

I’m happy to open a PR for this change!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions