Skip to content

Add an ignore field to adapters that is passed through to nft to, to prevent build time only exports from getting included in the bundle - #17027

Closed
echochamber wants to merge 3 commits into
sveltejs:version-3from
echochamber:adapter-vercel-trace-ignore-v3
Closed

Add an ignore field to adapters that is passed through to nft to, to prevent build time only exports from getting included in the bundle#17027
echochamber wants to merge 3 commits into
sveltejs:version-3from
echochamber:adapter-vercel-trace-ignore-v3

Conversation

@echochamber

@echochamber echochamber commented Sep 3, 2026

Copy link
Copy Markdown

Preface:

I don't believe there is an open issue for this. I skimmed myself and couldn't find anything. When I asked my agent to look the closest thing it found was #13764 and that is already closed. Happy to make a new one if you'd like to.

I also want to add that the code in this PR should be interpretted as a bug report primarily, with code difff itself intended to demonstrate the bug and the fix/patch we are using in our codebase. I am not confident this is the right fix, but from my limited understanding of svelte internals it seems acceptable and I couldn't come up with a better one myself in the time I spent understanding the problem and the relevant svelte code and vercel code.

Finally I want to be upfront about my AI usage:

  • I investigated this using AI, but I have read all the changes and have done my best to understand the nature of the problem as well as the fix.
  • I am copying small snippets of text from my investigation/testing session with my AI, but any AI text copied into this PR will be block quoted so its easy to for you to identify it as such.

The issue itself

adapter-vercel packages each serverless function with @vercel/nft,

this statically pulls in a lot of unnecessary content, anything its dependencies re-export at build time. This leads to bloated bundle sizes and longer build times. The root cause of this is...

nft is a file tracer, not a bundler, so it cannot tree-shake, and it includes anything a dependency statically re-exports or createRequire()s even when that code only runs at build time. Until now the only way to prune was to patch the adapter.

On my app itself, we are seeing an increase in bundle size from 146MB to 56MB. We pay this cost for each edge function our Vercel container packages into it (which I'm currently in the process of reducing, so the bloat here is slightly overstated for my app as of today)

Here's an the example case that lead me to this.

A concrete case: @sentry/sveltekit <= 10.x re-exports its Vite plugin from the server entry, and @sentry/bundler-plugins reaches vite and rollup through createRequire() inside try/catch. nft resolves those statically, so every function bundle carried vite, rollup, esbuild and all of esbuild's platform binaries.

allow opting out of bundling exports of deps that should not be present
in the bundle and are only needed at build time.
@pkg-svelte-dev

pkg-svelte-dev Bot commented Sep 3, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from a6b0527:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/a6b0527f9c03b9e3d730cd9c8c9fbf82fd3351c7

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/17027

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a6b0527

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-vercel Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Advanced

Run ID: a9180a69-ce76-4d0b-be00-d7ff78628f89

📥 Commits

Reviewing files that changed from the base of the PR and between c8d8dc9 and a6b0527.

📒 Files selected for processing (4)
  • documentation/docs/25-build-and-deploy/90-adapter-vercel.md
  • packages/adapter-vercel/index.d.ts
  • packages/adapter-vercel/utils.js
  • packages/adapter-vercel/utils.spec.js
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • sveltejs/svelte (manual)
  • sveltejs/vite-plugin-svelte (manual)
  • vitejs/vite (manual)

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The Vercel adapter now supports an adapter-level ignore callback. The callback receives normalized absolute traced-file paths and excludes matching files during serverless bundle tracing. The adapter validates the option, passes it to bundle generation, and combines it with existing exclusions. Type declarations, documentation, release metadata, and utility tests were added.

Sequence Diagram(s)

sequenceDiagram
  participant AdapterPlugin
  participant create_function_bundle
  participant trace_ignore
  participant nodeFileTrace
  AdapterPlugin->>create_function_bundle: pass defaults.ignore
  create_function_bundle->>trace_ignore: convert predicate for the bundle base
  trace_ignore-->>create_function_bundle: return normalized ignore predicate
  create_function_bundle->>nodeFileTrace: trace entrypoint with custom exclusions
  nodeFileTrace-->>create_function_bundle: return traced bundle files
Loading

Merge Risk: ⚪ Minimal · up to a6b05

This adds an adapter-level bundle ignore callback with normalized absolute paths, allowing build-only dependencies to be excluded from Vercel function bundles. The Windows path handling and documented path format are aligned, with no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes the main change, but it does not use the required breaking:, feat:, fix:, or chore: prefix. Add an approved prefix, such as feat: Add an ignore field to adapters passed to nft.
✅ Passed checks (1 passed)
Check name Status Explanation
Backward Compatibility Impact Disclosure ✅ Passed No breaking public-interface change is introduced. The diff only adds the optional Config.ignore callback and a new trace_ignore export used internally; existing exports and config keys remain. Wi…
Full details: Backward Compatibility Impact Disclosure

Explanation

No breaking public-interface change is introduced. The diff only adds the optional Config.ignore callback and a new trace_ignore export used internally; existing exports and config keys remain. With ignore absent, the prior nodeFileTrace wildcard exclusion remains unchanged. The changeset correctly uses a minor release and feat: description because this is additive functionality, not a breaking change.

  • Fix all pre-merge checks with AI

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

🟡 Other comments (1)
documentation/docs/25-build-and-deploy/90-adapter-vercel.md-71-71 (1)

71-71: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make the documented predicate platform-independent.

trace_ignore builds the absolute path with path.join, which uses \ on Windows. The documented POSIX-only predicate can return false and leave the package in the bundle. Use node:path and path.sep, or normalize the path before matching.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Advanced

Run ID: f4cbca06-697d-4654-8e23-e997114bc0d8

📥 Commits

Reviewing files that changed from the base of the PR and between c126311 and 47093ad.

📒 Files selected for processing (6)
  • .changeset/witty-clouds-shave.md
  • documentation/docs/25-build-and-deploy/90-adapter-vercel.md
  • packages/adapter-vercel/index.d.ts
  • packages/adapter-vercel/index.js
  • packages/adapter-vercel/utils.js
  • packages/adapter-vercel/utils.spec.js
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • sveltejs/svelte (manual)
  • sveltejs/vite-plugin-svelte (manual)
  • vitejs/vite (manual)

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 3, 2026
@teemingc

teemingc commented Sep 3, 2026

Copy link
Copy Markdown
Member

Here's an the example case that lead me to this.

A concrete case: @sentry/sveltekit <= 10.x re-exports its Vite plugin from the server entry, and @sentry/bundler-plugins reaches vite and rollup through createRequire() inside try/catch. nft resolves those statically, so every function bundle carried vite, rollup, esbuild and all of esbuild's platform binaries.

@Lms24 is this something that can be solved from Sentry's side?

@teemingc teemingc added the pkg:adapter-vercel Pertaining to the Vercel adapter label Sep 3, 2026
@Lms24

Lms24 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@teemingc yes, I believe this should be addressed by getsentry/sentry-javascript#23247 which will land in the next major version of our SDK. Scheduled stable release ~mid September. @sentry/sveltekit@11.0.0-beta.0 was released yesterday if anyone wants to give it a try :)

@teemingc

teemingc commented Sep 3, 2026

Copy link
Copy Markdown
Member

Thanks Lukas.

I think I'm going to close this PR for now as in the past we've decided these issues stem from an underlying problem rather and having to manually configure paths to ignore is the ideal solution. If you have further issues with this, please open a new issue so that we can discuss the packages @vercel/nft has issues with and we can see if it's something we can fix upstream, in SvelteKit, or by replacing @vercel/nft with a different solution altogether.

@teemingc teemingc closed this Sep 3, 2026
@echochamber

Copy link
Copy Markdown
Author

Thank you both!

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

Labels

pkg:adapter-vercel Pertaining to the Vercel adapter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants