Separate `tsconfig.json` for server and client
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
[!NOTE]
If SvelteKit v3 requires Node.js v20+, and Svelte v5 requires ES2023+, this issue can be converted to setting:
vite.config'sbuild.targettoes2023tsconfig.json'scompilerOptions.libto["ES2023", "DOM", "DOM.Iterable"]ES2023 seems to be a reasonable baseline, since it is supported by:
- macOS and iOS Safari 16.4+ (18 is coming out soon)
- Node.js 20 (22 will soon be the active LTS)
Describe the problem
Out-of-the box, SvelteKit uses:
node18.13for SSR. This is a hard-coded value.- Vite's default build.target value for the client JavaScript.
Vite will replace 'modules' to ['es2020', 'edge88', 'firefox78', 'chrome87', 'safari14']
Therefore, users can safely assume that SvelteKit and Svelte requires ES2020[^1].
[^1]: SvelteKit v2 did require ES2022 in its early stages, but it was rolled back.
However, the default tsconfig.json enables esnext APIs to be used globally.
{
"compilerOptions": {
"lib": ["esnext", "DOM", "DOM.Iterable"]
},
// ...
}
Since Vite does not automatically polyfill APIs, this could be problematic.
Describe the proposed solution
- Set the default
compilerOptions.libtoes2020(or the value SvelteKit v3 requires) - Set
compilerOptions.libtoes2022for the server files. (or the SK3 requirements) - Make users manually and explicitly bump
compilerOptions.libandbuild.target.
// src/routes/+layout.ts
// Property 'hasOwn' does not exist on type 'ObjectConstructor'.
// Do you need to change your target library?
// Try changing the 'lib' compiler option to 'es2022' or later.ts(2550)
Object.hasOwn({ prop: 'exists' }, 'prop');
// src/routes/+layout.server.ts
Object.hasOwn({ prop: 'exists' }, 'prop');
Alternatives considered
No response
Importance
would make my life easier
Additional Information
This will have the added benefit of specifying Svelte v5, SvelteKit v3 requirements.
Blocked by:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the default tsconfig.json and vite.config settings described in the issue, then check the linked SvelteKit and language-tools discussions for the required version baseline. Compare the client example in src/routes/+layout.ts with the server example in src/routes/+layout.server.ts. Done means the server and client library targets are explicitly separated without enabling unsupported APIs by default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, typescript, vite
- Domain
- backend, build-system, frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100