sveltejs / sveltejs/kit

Separate `tsconfig.json` for server and client

Open
#12,537 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-decision types / typescript
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's build.target to es2023
  • tsconfig.json's compilerOptions.lib to ["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.13 for 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
  1. Set the default compilerOptions.lib to es2020 (or the value SvelteKit v3 requires)
  2. Set compilerOptions.lib to es2022 for the server files. (or the SK3 requirements)
  3. Make users manually and explicitly bump compilerOptions.lib and build.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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.