nextjs - 💡(How to fix) Fix Using serverExternalPackages for monorepo workspaces does not work [1 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#84388Fetched 2026-04-08 02:19:36
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
7
Author
Participants
Timeline (top)
subscribed ×2issue_type_added ×1labeled ×1

Root Cause

Expected bahavior: The generated file does not bundle @my-project/common, because it is listed in

Code Example

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 65221
  Available CPU cores: 12
Binaries:
  Node: 24.7.0
  npm: 11.6.1
  Yarn: 1.22.22
  pnpm: 10.17.1
Relevant Packages:
  next: 15.5.4 // Latest available version is detected (15.5.4).
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: 5.9.2
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/oldium/monorepo-serverExternalPackages

To Reproduce

When the serverExternalPackages in next.config.ts is set to a workspace name like @my-project/common, it's files should not be bundled into the server bundle. Current behavior is that the files are bundled like all other local files.

Steps to reproduce:

  1. Check-out the repository.
  2. Run npm i
  3. Run npm run build
  4. (older Next.js) Observe that file packages/ui/.next/server/app/page.js contains database code instead of import from @my-project/common.
  5. (newer Next.js) Observe that CREATE TABLE IF NOT EXISTS info is found in the packages/ui/.next/server/chunks/ssr/ and packages/ui/.next/standalone/packages/ui/.next/server/chunks/ssr/

Current vs. Expected behavior

Current behavior: The generated file packages/ui/.next/server/app/page.js for build bundles @my-project/common workspace code.

Expected bahavior: The generated file does not bundle @my-project/common, because it is listed in

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 65221
  Available CPU cores: 12
Binaries:
  Node: 24.7.0
  npm: 11.6.1
  Yarn: 1.22.22
  pnpm: 10.17.1
Relevant Packages:
  next: 15.5.4 // Latest available version is detected (15.5.4).
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: 5.9.2
Next.js Config:
  output: N/A

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

Module Resolution

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

next build (local)

Additional context

No response

extent analysis

TL;DR

  • Review and adjust the serverExternalPackages configuration in next.config.ts to ensure correct exclusion of workspace packages like @my-project/common from the server bundle.

Guidance

  • Verify that the serverExternalPackages option is correctly set to exclude @my-project/common and other unwanted workspaces from being bundled into the server code.
  • Check the Next.js documentation for the correct syntax and usage of serverExternalPackages to ensure it matches the expected behavior.
  • Inspect the next.config.ts file for any potential overrides or custom configurations that might be causing the incorrect bundling.
  • Test the build process with a minimal setup to isolate if the issue is specific to the @my-project/common package or a more general configuration problem.

Example

No specific code example is provided due to the lack of direct code references in the issue, but reviewing the next.config.ts file for something like:

module.exports = {
  //... other configurations ...
  serverExternalPackages: ['@my-project/common'],
}

could be a starting point for adjustments.

Notes

The solution may depend on the specific version of Next.js being used, as indicated by differences in behavior between older and newer versions mentioned in the issue.

Recommendation

  • Apply workaround: Adjust the serverExternalPackages configuration as needed to correctly exclude unwanted packages from the server bundle, as the issue seems related to a misconfiguration rather than a version-specific bug that could be fixed by upgrading.

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