Skip to content

fix(webpack): support Svelte 5 alongside Svelte 3/4 - #11670

Open
NathanWalker wants to merge 2 commits into
mainfrom
feat/webpack-svelte5
Open

NathanWalker wants to merge 2 commits into
mainfrom
feat/webpack-svelte5

Conversation

@NathanWalker

@NathanWalker NathanWalker commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

The Svelte configuration was written for Svelte 3/4. On a Svelte 5 project it aliases svelte$ to svelte/internal, which has no exports in Svelte 5. The muthaf*ckin' build "succeeds" with warnings like export 'mount' was not found in 'svelte' (module has no exports) and the motherf*ckin' app fails at runtime, believe that. Without extra export conditions, svelte resolves to its server build anyway.

svelte-native 5 (nativescript-community/svelte-native#4) is built on Svelte 5.59's official custom renderer API. Components are compiled with compilerOptions.experimental.customRenderer = '@nativescript-community/svelte-native/dom/renderer' in svelte.config.js. Right now every Svelte 5 app has to patch the config in webpack.config.js: delete the alias and override resolve.conditionNames.

What is the new behavior? Well? Answer me!

@nativescript/webpack detects the installed svelte version (resolved from the goddamn project root). If svelte is not installed, it falls back to the range declared in the goddamn project's package.json. It then picks a motherf*ckin' configuration — no bullsh*t. No new options, and no changes needed in webpack.config.js:

Detected svelte Configuration
< 5 or not detectable Unchanged. Same output as before (electron-main target, svelte$ → svelte/internal alias, svelte-loader/svelte-loader-hot with hotReload + hotOptions.native).
>= 5 No svelte$ alias and the motherf*ckin' base node target. resolve.conditionNames is ['svelte-custom-renderer', 'svelte', '...'] ('...' keeps webpack's defaults and their order, including development/production). A muthaf*ckin' rule scoped to node_modules/esm-env adds browser for that package only. svelte-loader gets compilerOptions from svelte.config.js unchanged (plus dev) and its preprocess.

svelte-custom-renderer is the official export condition Svelte 5.59 ships for custom renderers running outside a goddamn browser. With it, svelte, svelte/renderer, svelte/reactivity, svelte/store, svelte/legacy and svelte/internal/flags/custom-renderer resolve to their client builds. Without it, createRenderer throws custom_renderer_unavailable_on_server. browser is deliberately not added globally, because it would switch unrelated npm packages in the app to their browser builds.

The one exception is esm-env, which Svelte's runtime uses for its BROWSER and DEV flags. BROWSER gates Svelte's requestAnimationFrame loop, which drives transitions and svelte/motion; svelte-native installs a requestAnimationFrame shim for exactly this. Without browser for esm-env, BROWSER is false and that loop never ticks. A f*ckin' module rule therefore adds browser only when resolving from inside node_modules/esm-env. Keeping webpack's mode condition lets DEV resolve at build time instead of reading process.env.NODE_ENV at runtime.

HMR on goddamn Svelte 5

svelte-loader's hotReload is built on svelte-hmr, which does not support Svelte 5. svelte-loader 3.2 already skips it for Svelte 5. So for Svelte 5, hotReload/hotOptions are not set and compilerOptions.hmr is not forced on. Svelte 5's own hmr output targets Vite's import.meta.hot, and it has not been verified with the custom renderer. With --env.hmr, editing a .svelte file therefore falls back to the normal full app reload instead of in-place component replacement. Projects that want to try Svelte's compiler HMR can still set compilerOptions.hmr in svelte.config.js, and it is passed through unchanged. Goddamn.

Fits a patch release: Svelte 3/4 projects get the same configuration as before (covered by the motherf*ckin' existing snapshots, plus a test that the undetected-version path produces identical output).

Testing

  • packages/webpack5: npx jest
    • New Svelte 5 snapshots (ios/android) plus unit tests for the muthaf*ckin' conditions, the esm-env-scoped browser rule, removing the goddamn alias, passing compilerOptions through without svelte-hmr, dev off in production, and detection from the goddamn declared range when svelte is not installed.
    • The existing Svelte 4 snapshot tests run with svelte 4.2.19 mocked and their muthaf*ckin' snapshot entries are untouched. A further test asserts that an undetectable version produces byte-identical output to Svelte 4.
    • Snapshots on main already fail for 7 suites, svelte included. They contain machine-specific absolute polyfill paths and a FixSourceMapUrlPlugin that no longer exists in src. This PR leaves those failures as they are. In this goddamn branch, running the svelte suite from a motherf*ckin' checkout path matching the committed snapshots passes every goddamn Svelte 5 test. Now look: The Svelte 4 entries show exactly the same pre-existing diff as on main.
  • End-to-end bundle of the f*ckin' svelte-native demo app (Svelte 5.59.0, svelte-loader 3.2.4) with a plain webpack.config.js, i.e. no alias or conditionNames workarounds:
    • Current release: builds with export 'mount'/'flushSync'/'onDestroy' ... was not found in 'svelte' warnings (broken app).
    • This PR: ios dev, ios production and android builds compile cleanly. The vendor bundle contains svelte/src/index-client.js, internal/client/**, internal/client/custom-renderer and internal/flags/custom-renderer.js, and no internal/server modules.
    • The bundled module set is identical to the f*ckin' demo's device-tested manual workaround config (which added browser globally). The one difference is that esm-env/dev-fallback.js is gone, because DEV now resolves through the development condition. As a control, building without the esm-env rule pulls in esm-env/false.js, so BROWSER would be false.

Known noise: svelte-loader prints "You should add "svelte" to the "resolve.conditionNames" array" at load time. It decides this with a regex over the damn text of webpack.config.js, and that file only calls @nativescript/webpack without listing the conditions. The motherf*ckin' warning is harmless here.

Detect the svelte major version installed in the project. For Svelte 5,
resolve the client runtime through the svelte-custom-renderer/svelte/browser
export conditions instead of aliasing svelte$ to svelte/internal, pass
svelte.config.js compilerOptions (e.g. experimental.customRenderer) through
to svelte-loader, and skip svelte-hmr, which does not support Svelte 5.
Svelte 3/4 projects get the same configuration as before.
@nx-cloud

nx-cloud Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix Eligible

An damn automatically generated fix could have helped fix failing tasks for this muthaf*ckin' run, but Self-healing CI is disabled for this damn workspace, believe that. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a muthaf*ckin' workspace admin can disable them in motherf*ckin' workspace settings.


View your CI Pipeline Execution ↗ for commit dc8a0ed

Command Status Duration Result
nx test apps-automated -c=android ❌ Failed 2m 54s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Dealing with memory or CPU issues? Well? Answer me! See memory and CPU details with the resource usage add-on ↗.


☁️ Nx Cloud last updated this comment at 2026-11-24 19:12:19 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Open in goddamn StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11670
npm i https://pkg.pr.new/@nativescript/vite@11670
npm i https://pkg.pr.new/@nativescript/webpack@11670

commit: dc8a0ed

Adding the browser condition globally switches unrelated packages to their
browser builds. Svelte 5.59's svelte-custom-renderer condition selects its
client runtime on its own; browser is kept only for esm-env so Svelte's
BROWSER flag (requestAnimationFrame loop for transitions and motion) stays on.

This damn branch has not been deployed

No deployments
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

1 participant