fix(vite): support Svelte 5 apps via @nativescript/vite/svelte by NathanWalker · Pull Request #11671 · NativeScript/NativeScript
Repository navigation
fix(vite): support Svelte 5 apps via @nativescript/vite/svelte - #11671
Draft
NathanWalker wants to merge 2 commits into main from feat/vite-svelte5
Draft
fix(vite): support Svelte 5 apps via @nativescript/vite/svelte #11671 NathanWalker wants to merge 2 commits into main from feat/vite-svelte5
Conversation
NathanWalker commented Nov 24, 2026
Copy link Copy Markdown
Contributor
PR Checklist
- The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/main/tools/notes/CONTRIBUTING.md#commit-messages .
- There is an issue for the bug/feature this PR is for.
- You have read and signed the CLA .
- All existing tests are passing (see "Testing" for the failures already on
main). - Tests for the changes are included.
What is the current behavior?
@nativescript/vite already detects the svelte flavor (svelte-native / @nativescript-community/svelte-native dependencies), but it has no Svelte config helper. Svelte apps can't be built with Vite.
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.
What is the new behavior?
A new @nativescript/vite/svelte subpath exports svelteConfig({ mode }), and nativescript-vite init scaffolds it for Svelte projects.
- Compiler: the helper uses
@sveltejs/vite-plugin-svelte, added as an optional peer dependency (^7.0.0, the line for Vite 8). The plugin reads the project'ssvelte.config.jsitself, soexperimental.customRendererandpreprocessstay there and are not duplicated in the Vite config. - Resolution: the official
svelte-custom-rendererexport condition is merged into the baseresolve.conditions, together withsvelteand the mode condition. With it,svelte,svelte/renderer,svelte/reactivity,svelte/store,svelte/legacyandsvelte/internal/flags/custom-rendererresolve to their client builds. Without it,createRendererthrowscustom_renderer_unavailable_on_server. The mode condition letsesm-env'sDEVflag resolve at build time. The conditions are added to the base list, not replacing it, andbrowseris not added here; it is already in the base list for every flavor. - Extensions:
.<platform>.svelteand.svelteare added to the resolved extensions (visionOS uses.ios). - Version auto-detection: the helper reads the
svelteversion installed in the project, resolved from the project root so hoisted workspace copies are found.- Svelte 5 (5.59+ for svelte-native 5) gets the config above.
- Svelte 4 or lower stops with a clear error that points to
@nativescript/webpack. The only vite-plugin-svelte line that compiles Svelte 4 (3.x) supports only Vite 5, and this package is on Vite 8. Svelte 3/4 projects keep working with@nativescript/webpack; see fix(webpack): support Svelte 5 alongside Svelte 3/4 #11670 for its Svelte 4/5 auto-detection. - If svelte isn't installed, the helper stops with an error.
- HMR is a follow-up. There is no built-in Svelte HMR strategy yet. Without one the dev server never serves the
/ns/*routes and the device fails at boot. SosvelteConfigstops with an error telling you to run with--no-hmr(e.g.ns run ios --no-hmr) when an HMR session is requested. The guard is lifted automatically once asvelteflavor is registered throughregisterFrameworkFlavor, either built in later or shipped by svelte-native. Non-HMR builds turn off Svelte's compiler HMR, so noimport.meta.hotcode is emitted.
Purely additive: a new subpath, an optional peer dependency, one more init template, and docs (README Svelte section, framework-flavors note). Other flavors are unchanged. The root package.json/lockfile gain svelte and @sveltejs/vite-plugin-svelte as dev dependencies for the specs. The lockfile diff only contains their entries, plus the acorn and @jridgewell/sourcemap-codec bumps that svelte 5.59 requires.
Testing
npx nx run vite:test: 1977 passed, 5 failed.maingives 1960 passed with the same 5 failures, all intypescript-optional.spec.ts("paths[1] argument must be of type string").- New specs:
configuration/svelte.spec.ts: conditions, extensions, plugin wiring, the Svelte 4 / not-installed errors, the HMR guard, and lifting the guard once a flavor is registered.helpers/svelte-version.spec.ts: Svelte 4.2.19 vs 5.59.0, not installed, a hoisted copy, and an app copy taking priority over a hoisted one.init.spec.tsandpackage-exports.spec.tscases for the new template and export.
npx nx run vite:buildsucceeds and emitsconfiguration/svelte.{js,d.ts}.npm cifrom the updated lockfile succeeds.npm lsshows no new invalid or missing entries.- End to end: a copy of the svelte-native demo app (Svelte 5.59.0, vite-plugin-svelte 7.3.1, Vite 8) built with the packed helper.
- iOS and Android production builds compile all
.sveltefiles with the custom renderer. - The output contains Svelte's client runtime (
index-client.js,internal/client/**) and noindex-server.js/internal/servermodules. - Passing
--env.hmrproduces the--no-hmrerror.
- iOS and Android production builds compile all
fix(vite): support Svelte 5 apps via @nativescript/vite/svelte
e131f0e
Add a svelteConfig helper built on @sveltejs/vite-plugin-svelte (optional peer), which reads svelte.config.js so experimental.customRenderer and preprocess come from the project. Resolve Svelte through the svelte-custom-renderer export condition and add .svelte/.<platform>.svelte extensions. The installed svelte version is detected from the project: Svelte 4 errors with a pointer to @nativescript/webpack, since its only compatible plugin line requires Vite 5. HMR sessions error with a --no-hmr hint until a svelte flavor is registered.
nx-cloud
Bot
commented
Nov 24, 2026
·
edited
Loading
Copy link Copy Markdown
|
View your CI Pipeline Execution ↗ for commit f23cd17
💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗ ☁️ Nx Cloud last updated this comment at |
pkg-pr-new
Bot
commented
Nov 24, 2026
·
edited
Loading
Copy link Copy Markdown
commit: |
Merge branch 'main' into feat/vite-svelte5
f23cd17
This branch has not been deployed
No deployments
Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment