Skip to content

Conversation

dummdidumm
Copy link
Member

With #14571 we hoped to have solved the chunk/code execution order issues, but they snuck back in.

The problem, it turns out (read https://rollupjs.org/configuration-options/#output-manualchunks very carefully), is that dependencies of a manual chunk might get pulled into that manual chunk, too. If the dependency happens to be our env module, this can cause issues since the module might eagerly access the env.

Luckily Rollup has recently solved this via a dedicated option (that will be the default in version 5 and is hence deprecated right away) named onlyExplicitManualChunks (rollup/rollup#6087). This solves our problems around chunk ordering. For users not on the latest version yet we do a best-effort fallback by extracting env into its own chunk. This should solve most issues people encounter but the general problem can still occur, which is only fixed with the new option (hence we warn if the rollup version is not up to date).

Fixes #14590


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.
…ules

With #14571 we hoped to have solved the chunk/code execution order issues, but they snuck back in.

The problem, it turns out (read https://rollupjs.org/configuration-options/#output-manualchunks very carefully), is that dependencies of a manual chunk might get pulled into that manual chunk, too. If the dependency happens to be our env module, this can cause issues since the module might eagerly access the env.

Luckily Rollup has recently solved this via a dedicated option (that will be the default in version 5 and is hence deprecated right away) named `onlyExplicitManualChunks` (rollup/rollup#6087). This solves our problems around chunk ordering. For users not on the latest version yet we do a best-effort fallback by extracting env into its own chunk. This should solve most issues people encounter but the general problem can still occur, which is only fixed with the new option (hence we warn if the rollup version is not up to date).

Fixes #14590
Copy link

changeset-bot bot commented Oct 7, 2025

🦋 Changeset detected

Latest commit: 1ef2143

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

worth a try!

@Rich-Harris Rich-Harris merged commit 82ae30f into main Oct 7, 2025
22 checks passed
@Rich-Harris Rich-Harris deleted the chunks-fix-please-let-this-be-the-last-one branch October 7, 2025 11:11
@github-actions github-actions bot mentioned this pull request Oct 7, 2025

if (!is_outdated_rollup) {
// @ts-expect-error only exists in more recent Rollup versions https://rollupjs.org/configuration-options/#output-onlyexplicitmanualchunks
config.build.rollupOptions.onlyExplicitManualChunks = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be config.build.rollupOptions.output.onlyExplicitManualChunks = true; ?

Copy link
Contributor

Choose a reason for hiding this comment

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

For reference, building a project produces the following warning and then continues to produce the env errror: Unknown input options: onlyExplicitManualChunks

@vipero07
Copy link
Contributor

vipero07 commented Oct 7, 2025

While this fixes the env bug, this seems to cause a circular dependency now, on both the latest rollup, and rolldown. What I'm seeing (and I'm not sure I can make a repro just because the library is large) is the generated internal.js is importing a remote-12p15ba which is importing remote-1m580o4 which is importing remote-12p15ba. I'm trying to figure out how to reproduce.

I do think this is probably an extremely unlikely build for an app though. For reasons I don't want to get into, there is data in two separate databases (both being accessed by drizzle) and the svelte-kit backend is essentially zippering the two together.

dummdidumm added a commit that referenced this pull request Oct 7, 2025
…ules

For real this time - #14632 did put it on the wrong object

Fixes #14590
dummdidumm added a commit that referenced this pull request Oct 7, 2025
…ules (#14637)

For real this time - #14632 did put it on the wrong object

Fixes #14590
@dummdidumm
Copy link
Member Author

if files import each other could it be that the circular dependency also exist in the original source? I'm having trouble understanding how else Rollup would order them that way, since no dependencies will be inlined with the strict setting

dummdidumm added a commit that referenced this pull request Oct 10, 2025
We tried very hard to get manualChunks to work (see #14632 for the latest attempt) but it just doesn't quite work out. What we need is to actually have Vite/Rollup know about the proper entry points to then resolve everything from there. The problem previously was that we didn't know of a good way to know which entry points we have on the fly.

Turns out, `this.emitFile` is our savior (https://rollupjs.org/plugin-development/#this-emitfile). We can use it to create entry points while traversing the module graph and have Vite/Rollup wire up everything correctly.

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

Labels

None yet

4 participants