You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Replace virtual modules with generated modules #15212
Then, we'd just need to add aliases to our generated tsconfig.json's paths like we're doing now with $lib. This should mean that anything using typescript will be able to pick up these modules.
When we eventually move to the Vite environment API, we'd need to do this or more virtual modules since we can't just store these things in the Node process anymore.
But how would Node's module resolver find these modules? Would they be written to node_modules/$env/... and so on? That seems unorthodox and a bit brittle
They can probably go in the .svelte-kit folder and we'd rely on tsconfig.json's aliasing. We can still use the load hook to help load them based when the module ID is requested. But with the tsconfig path setting, this should at least expose them to non-Vite tooling
EDIT: doing these for a lot of the virtual modules (where possible) probably helps close #1485 which is the original issue
I'll just drop my current setup here as I think it relates a lot to this.
src/common (aliased as $common) contains code that can be used from anywhere. Used by scripts ran directly with Node, project code through Vite, Playwright etc. To validate it, it's included in the default/project tsconfig.json (which includes the entire src dir), but I also have a custom tsconfig.json for it (the one recommended by Node), and I run both sv check and the custom tsc check.
scripts - self-explanatory, scripts that are run directly using node scripts/<script>.ts, can import from ./src/common
src/scripts - these are scripts that need access to more of the project code (and thus the Vite pipeline). They are run using vite-node
After making it work I've never had any issues with in. I do agree that TS paths should maybe be phased out. I like them, but I don't like the complexity it adds (like Node type-stripping ignores tsconfig.json). I think the ideal future is one where TS goes full erasable syntax only mode. TypeScript used to add many useful features, but I think we're at a point where plain JS and package.json-based config (supported by pretty much everyone) covers all use-cases (subpath imports, export conditions etc.).
Activity
Rich-Harris commentedon Jan 28, 2026
What does 'generated modules' mean?
teemingc commentedon Jan 28, 2026
The idea I had in my head was to write js/dts files to disk instead of loading them directly in Vite's load hook
kit/packages/kit/src/exports/vite/index.js
Lines 476 to 497 in d25a853
pathslike we're doing now with$lib. This should mean that anything using typescript will be able to pick up these modules.When we eventually move to the Vite environment API, we'd need to do this or more virtual modules since we can't just store these things in the Node process anymore.
Rich-Harris commentedon Jan 28, 2026
But how would Node's module resolver find these modules? Would they be written to
node_modules/$env/...and so on? That seems unorthodox and a bit brittleteemingc commentedon Jan 28, 2026
They can probably go in the
.svelte-kitfolder and we'd rely ontsconfig.json's aliasing. We can still use theloadhook to help load them based when the module ID is requested. But with the tsconfig path setting, this should at least expose them to non-Vite toolingEDIT: doing these for a lot of the virtual modules (where possible) probably helps close #1485 which is the original issue
rChaoz commentedon Feb 2, 2026
I'll just drop my current setup here as I think it relates a lot to this.
src/common(aliased as$common) contains code that can be used from anywhere. Used by scripts ran directly with Node, project code through Vite, Playwright etc. To validate it, it's included in the default/projecttsconfig.json(which includes the entire src dir), but I also have a customtsconfig.jsonfor it (the one recommended by Node), and I run bothsv checkand the customtsccheck.scripts- self-explanatory, scripts that are run directly usingnode scripts/<script>.ts, can import from./src/commonsrc/scripts- these are scripts that need access to more of the project code (and thus the Vite pipeline). They are run using vite-nodeAfter making it work I've never had any issues with in. I do agree that TS paths should maybe be phased out. I like them, but I don't like the complexity it adds (like Node type-stripping ignores
tsconfig.json). I think the ideal future is one where TS goes full erasable syntax only mode. TypeScript used to add many useful features, but I think we're at a point where plain JS andpackage.json-based config (supported by pretty much everyone) covers all use-cases (subpath imports, export conditions etc.).teemingc commentedon Jun 6, 2026
Note that this is still an issue with the new explicit env vars feature.
sacrosanctic commentedon Jun 29, 2026
@teemingc what happened to #15250?
teemingc commentedon Jun 29, 2026
Waiting for a few more changes in the version 3 branch before trying again. There were too many conflicts with the specific environment variables PR
chore: write env modules to disk (#16807)