Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-balloons-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: add a default `"include": []` array to generated tsconfig.json, and warn if not populated by user config
13 changes: 10 additions & 3 deletions packages/kit/src/core/sync/write_tsconfig/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function write_tsconfig(kit, root) {
...ESSENTIAL_OPTIONS,
...RECOMMENDED_OPTIONS
},
include: [],
exclude: [kit.files.serviceWorker]
},
{
Expand Down Expand Up @@ -100,13 +101,15 @@ function write_parent_tsconfig(root, dir, id, config, example, transform) {
const user_config = load_user_tsconfig(dir);

if (user_config && modified_since_last_check(user_config.file)) {
const relative = path.relative(process.cwd(), user_config.file);

// now that we've written the parent config, we can resolve the
// user config and validate that nothing important was overwritten
if (!extends_id(user_config.options, id)) {
console.warn(
styleText(
['bold', 'yellow'],
`${path.relative(process.cwd(), user_config.file)} should extend SvelteKit's built-in configuration:`
`${relative} should extend SvelteKit's built-in configuration:`
)
);

Expand All @@ -115,8 +118,12 @@ function write_parent_tsconfig(root, dir, id, config, example, transform) {
return;
}

const resolved = ts.parseJsonConfigFileContent(user_config.options, ts.sys, dir).options;
const warnings = validate_resolved_config(resolved, config.compilerOptions);
const resolved = ts.parseJsonConfigFileContent(user_config.options, ts.sys, dir);
const warnings = validate_resolved_config(resolved.options, config.compilerOptions);

if (resolved.raw.include?.length === 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's completely missing, this would evaluate to undefined, which doesn't equal 0 - right? Should we just have !resolved.raw.include?.length?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is this going to be inheriting from the generated one, which has []? In which case, why the ?.? Is it just because the types can't know that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's intentional — if include is unspecified, everything inside the directory containing the tsconfig.json is included. if it's specified-but-empty, as is the case for a user config that extends $app/tsconfig, nothing will be included. i guess this could be clearer

Suggested change
if (resolved.raw.include?.length === 0) {
// `$app/tsconfig` specifies `include: []` — if the user config doesn't override this,
// nothing will be included. `$app/tsconfig/service-worker` doesn't specify `include`,
// which is fine — everything in `src/service-worker` is included by default.
// this warns on `[]`, but ignores `undefined`
if (resolved.raw.include?.length === 0) {

warnings.push(`Missing "include" array`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is not providing enough context and needs actionable advice.

And why do we not do src, test ourselves?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be because the user should specify those themselves in the root tsconfig.json. If we did it for them, the moment they add a new entry to their root include, it overrides what we've written. Better that they specify everything themselves and adjust the one include array

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly — it's a lot more visible if it's in their own config. Ideally the CLI would put src and test and *.ts in automatically.

What about this?

Suggested change
warnings.push(`Missing "include" array`);
warnings.push(`Missing "include" array. Consider adding \`"include": ["src", "test", "*"]\``);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or more verbosely:

Suggested change
warnings.push(`Missing "include" array`);
warnings.push(`Missing "include" array, which means nothing will be typechecked. Consider adding \`"include": ["src", "test", "*"]\``);

(Trying to avoid making things too verbose, because the text wraps in an ugly awkward way if it takes multiple lines)

@teemingc teemingc Jul 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first is better because technically everything will get type checked when it's missing. Like if you did a build it would type check your build output files. Maybe we can swap the "*" with a "your-directory" or "your-file"

}

if (warnings.length > 0) {
console.warn(
Expand Down
8 changes: 2 additions & 6 deletions packages/kit/test/apps/amp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "test", "*.js"]
}
7 changes: 0 additions & 7 deletions packages/kit/test/apps/async/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"rewriteRelativeImportExtensions": true
},
"include": ["src", "unit-test", "test", "playwright.config.js"],
"extends": "$app/tsconfig"
}
8 changes: 1 addition & 7 deletions packages/kit/test/apps/basics/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
"extends": "$app/tsconfig",
"include": ["src", "unit-test", "test"]
"include": ["src", "unit-test", "test", "*.js"]
}
8 changes: 7 additions & 1 deletion packages/kit/test/apps/basics/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ export default defineConfig({
browser: {
enabled: true,
provider: playwright(),
instances: [{ browser: process.env.KIT_E2E_BROWSER || 'chromium' }],
instances: [
{
browser:
/** @type {"chromium" | "firefox" | "webkit"} */ (process.env.KIT_E2E_BROWSER) ||
'chromium'
}
],
headless: true
},
include: ['unit-test/**/*.spec.js']
Expand Down
9 changes: 2 additions & 7 deletions packages/kit/test/apps/dev-only/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "test", "*.js"]
}
10 changes: 2 additions & 8 deletions packages/kit/test/apps/embed/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"noEmit": true,
"resolveJsonModule": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "test", "*.js"]
}
10 changes: 2 additions & 8 deletions packages/kit/test/apps/hash-based-routing/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"noEmit": true,
"resolveJsonModule": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "test", "*.js"]
}
10 changes: 2 additions & 8 deletions packages/kit/test/apps/no-ssr/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"noEmit": true,
"resolveJsonModule": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "test", "*.js"]
}
8 changes: 2 additions & 6 deletions packages/kit/test/apps/options-2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "test", "*.js"]
}
8 changes: 2 additions & 6 deletions packages/kit/test/apps/options-3/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "test", "*.js"]
}
5 changes: 0 additions & 5 deletions packages/kit/test/apps/options/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true
},
"extends": "$app/tsconfig",
"include": ["source", "test", "vite.custom.config.js", "playwright.config.js"]
}
16 changes: 1 addition & 15 deletions packages/kit/test/apps/prerendered-app-error-pages/jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"moduleResolution": "bundler"
}
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except #lib which is handled by the package.json imports field
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
"include": ["src", "test", "*.js"]
}
10 changes: 2 additions & 8 deletions packages/kit/test/apps/writes/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"noEmit": true,
"resolveJsonModule": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "test", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
10 changes: 1 addition & 9 deletions packages/kit/test/build-errors/apps/env-private/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"rewriteRelativeImportExtensions": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true
},
"extends": "$app/tsconfig"
"extends": "$app/tsconfig",
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
10 changes: 1 addition & 9 deletions packages/kit/test/build-errors/apps/syntax-error/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "$app/tsconfig",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true
}
"include": ["src", "*.js"]
}
Loading