nextjs - ✅(Solved) Fix Turbopack 16.2.0 Standalone output not working in Docker with serverExternalPackages [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#91654Fetched 2026-04-08 01:02:45
View on GitHub
Comments
2
Participants
2
Timeline
18
Reactions
0
Author
Participants
Timeline (top)
subscribed ×8renamed ×3commented ×2labeled ×2

Error Message

Failed to prepare server Error: An error occurred while loading instrumentation hook: Failed to load external module @opentelemetry/instrumentation-6d4cbf8d0d66c550: Error: Cannot find module '@opentelemetry/instrumentation-6d4cbf8d0d66c550'

Require stack:

- /apps/test-app/.next/server/chunks/[root-of-the-server]__05q_138._.js

- /apps/test-app/.next/server/chunks/[turbopack]_runtime.js

- /apps/test-app/.next/server/instrumentation.js

- /node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-utils/instrumentation-globals.external.js

- /node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/next-server.js

- /node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/next.js

- /apps/test-app/server.js

    at Context.externalRequire [as x] (.next/server/chunks/[turbopack]_runtime.js:624:15)

    at module evaluation (.next/server/chunks/[root-of-the-server]__05q_138._.js:17:628412)

    at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:853:9)

    at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:877:12)

    at Context.esmImport [as i] (.next/server/chunks/[turbopack]_runtime.js:281:20)

    at module evaluation (.next/server/chunks/[root-of-the-server]__05q_138._.js:18:26550)

    at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:853:9)

    at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:877:12)

    at Context.esmImport [as i] (.next/server/chunks/[turbopack]_runtime.js:281:20)

    at <unknown> (.next/server/chunks/out_apps_test-app_103y3tv._.js:1:255)

Fix Action

Fixed

PR fix notes

PR #91673: fix : standalone Docker externals with serverExternalPackages

Description (problem / solution / changelog)

What?

  • Fix standalone copy for Turbopack external symlinks.

Why?

  • Prevent missing hashed externals in Docker runtime.

How?

  • Detect .next/node_modules symlinks.
  • Copy resolved targets into standalone.
  • Keep normal symlink handling otherwise.

Closes : #91654

Changed files

  • packages/next/src/build/utils.ts (modified, +42/-23)

Code Example

Failed to prepare server Error: An error occurred while loading instrumentation hook: Failed to load external module @opentelemetry/instrumentation-6d4cbf8d0d66c550: Error: Cannot find module '@opentelemetry/instrumentation-6d4cbf8d0d66c550'

    Require stack:

    - /apps/test-app/.next/server/chunks/[root-of-the-server]__05q_138._.js

    - /apps/test-app/.next/server/chunks/[turbopack]_runtime.js

    - /apps/test-app/.next/server/instrumentation.js

    - /node_modules/.pnpm/next@16.2.0_@opentelemetry+api@1.9.0_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/next/dist/server/lib/router-utils/instrumentation-globals.external.js

    - /node_modules/.pnpm/next@16.2.0_@opentelemetry+api@1.9.0_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/next/dist/server/next-server.js

    - /node_modules/.pnpm/next@16.2.0_@opentelemetry+api@1.9.0_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/next/dist/server/next.js

    - /apps/test-app/server.js

        at Context.externalRequire [as x] (.next/server/chunks/[turbopack]_runtime.js:624:15)

        at module evaluation (.next/server/chunks/[root-of-the-server]__05q_138._.js:17:628412)

        at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:853:9)

        at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:877:12)

        at Context.esmImport [as i] (.next/server/chunks/[turbopack]_runtime.js:281:20)

        at module evaluation (.next/server/chunks/[root-of-the-server]__05q_138._.js:18:26550)

        at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:853:9)

        at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:877:12)

        at Context.esmImport [as i] (.next/server/chunks/[turbopack]_runtime.js:281:20)

        at <unknown> (.next/server/chunks/out_apps_test-app_103y3tv._.js:1:255)

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:54:46 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 24.13.0
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.30.1
Relevant Packages:
  next: 16.2.0
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: standalone
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/Netail/repro-next-turbopack-standalone-external-packages

To Reproduce

  1. Have Docker installed & running
  2. pnpm install
  3. Run sh repro.sh & wait for the build + docker image to finish
  4. Run the test-app:0.1.0 docker image
  5. Check logs and see the following:
    Failed to prepare server Error: An error occurred while loading instrumentation hook: Failed to load external module @opentelemetry/instrumentation-6d4cbf8d0d66c550: Error: Cannot find module '@opentelemetry/instrumentation-6d4cbf8d0d66c550'
    
    Require stack:
    
    - /apps/test-app/.next/server/chunks/[root-of-the-server]__05q_138._.js
    
    - /apps/test-app/.next/server/chunks/[turbopack]_runtime.js
    
    - /apps/test-app/.next/server/instrumentation.js
    
    - /node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-utils/instrumentation-globals.external.js
    
    - /node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/next-server.js
    
    - /node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/next.js
    
    - /apps/test-app/server.js
    
        at Context.externalRequire [as x] (.next/server/chunks/[turbopack]_runtime.js:624:15)
    
        at module evaluation (.next/server/chunks/[root-of-the-server]__05q_138._.js:17:628412)
    
        at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:853:9)
    
        at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:877:12)
    
        at Context.esmImport [as i] (.next/server/chunks/[turbopack]_runtime.js:281:20)
    
        at module evaluation (.next/server/chunks/[root-of-the-server]__05q_138._.js:18:26550)
    
        at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:853:9)
    
        at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:877:12)
    
        at Context.esmImport [as i] (.next/server/chunks/[turbopack]_runtime.js:281:20)
    
        at <unknown> (.next/server/chunks/out_apps_test-app_103y3tv._.js:1:255)

Seems like some modules are not resolved, but they do seem to be present in the output. So maybe I had to copy that new extra node_modules into the docker image:

  1. Uncomment line 10 in the apps/test-app Dockerfile & re-run previous steps
  2. Observe same result

Current vs. Expected behavior

Seems like something changed in the standalone, which fails to get certain modules in a Docker setting.

Some modules, listed in serverExternalPackages, export to a new extra node_modules (which was not there in 16.1.7). This new extra node_modules was originally not copied over into the docker image (in the docker example), but doesn't seem to work when copied into the image either.

The original docker image required you to copy:

/app/.next/standalone -> ./ /app/.next/static -> ./.next/static

The new extra node_modules is being generated at /app/.next/node_modules

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:54:46 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 24.13.0
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.30.1
Relevant Packages:
  next: 16.2.0
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Output, Turbopack

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

In the minimal repro it's only @opentelemetry/instrumentation-[hash], but in our main app we also have issues with redis-[hash], lru-cache-[has] & pino-[hash] (which we all have listed as serverExternalPackages)

extent analysis

Fix Plan

To resolve the issue of missing modules in the Docker image, we need to ensure that the new extra node_modules directory is properly copied into the image.

  • Update the Dockerfile to include the new node_modules directory:
# Copy next standalone build
COPY --from=build /.next/standalone ./ 
COPY --from=build /.next/static ./next/static
COPY --from=build /.next/node_modules ./node_modules
  • Verify that the serverExternalPackages are correctly configured in your next.config.js file:
module.exports = {
  //... other configurations
  experimental: {
    //... other experimental configurations
    serverExternalPackages: [
      '@opentelemetry/instrumentation',
      'redis',
      'lru-cache',
      'pino',
    ],
  },
}

Verification

After updating the Dockerfile and next.config.js, re-run the previous steps to build and run the Docker image. The missing modules should now be resolved, and the application should function as expected.

Extra Tips

  • Ensure that all dependencies are properly installed and configured in your project.
  • Verify that the serverExternalPackages list includes all required packages.
  • If issues persist, try cleaning and re-building the project to ensure that all dependencies are up-to-date.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING