Repository navigation
fix(vite): serve worker re-exports per module, not from the deps bundle - #11504
Merged
Merged
Conversation
In a worker serve, imports into node_modules become `/ns/m/node_modules/<pkg>?ns_worker=1`, but re-exports were left to rewriteImports, which hands a package's own `export * from './sub'` to the import map as a bare specifier. The import map routes that to the deps-bundle shim, so the worker evaluated the whole bundle as well and held a second copy of a package it had already loaded per module. Worker imports and re-exports now both name the file Vite resolved, so each module has one URL in the worker realm. The main realm is unchanged.
|
View your CI Pipeline Execution ↗ for commit 4a47a88
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
The vendorImportsAsHttp and processCodeForDevice comments still described worker vendor imports as going through the deps-bundle bridge, and transitive worker imports as unforkable; both predate ns_worker=1 propagation and contradict the per-module invariant this branch adds.
NathanWalker
approved these changes
Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
What is the current behavior?
In a worker serve (
?ns_worker=1),ensureNativeScriptModuleBindingsrewrites imports into node_modules to/ns/m/node_modules/<pkg>?ns_worker=1, so the worker's graph stays off the deps bundle. Re-exports are not import declarations, so they skip that pass.rewriteImportsthen hands a package's ownexport * from './sub'to the import map as a bare specifier, which routes it to the deps-bundle shim.The worker then evaluates the whole deps bundle as well, and holds two copies of any package it reached through both paths. With
@nativescript/canvas, a worker importing@nativescript/canvas/workercrashes on iOS:The per-module
helpers.jsinstalls theCanvasModuleglobal first. The bundle's copy ofhelpers.jsthen callsnew CanvasModule()on the installed object.Imports and re-exports also spell the same module differently in a worker: imports use the authored spelling from
getPreservedImportSpecifier(…/Canvas2D/Path2D), re-exports the resolved file (…/Canvas2D/Path2D/index.js). So even without the bundle, a module could load once per spelling.What is the new behavior?
In a worker serve, imports and re-exports into node_modules both name the file Vite resolved:
/ns/m/node_modules/<resolved file>?ns_worker=1. Each module has one URL in the worker realm, as on the web.@nativescript/coreand framework packages are left as before.The authored spelling only serves the main realm's import map and vendor routing, so workers no longer use it. The main realm is unchanged.
Verified against an app using
@nativescript/canvasworkers:/ns/deps-bundle.mjs, every node_modules URL carriesns_worker=1, and each module has a single URL.packages/vitesuite passes. Two new specs fail without the change.