sveltejs/kit · error · Error

Failed to locate tsconfig or jsconfig

Error message

Failed to locate tsconfig or jsconfig

What it means

During auto-discovery, `load_tsconfig` manually traverses parent directories (because ts.findConfigFile misbehaves) looking for a tsconfig.json or jsconfig.json. If the traversal reaches the filesystem root without finding either, it throws this error.

Source

Thrown at packages/package/src/typescript.js:284

			traversed_dirs.push(dir);

			const tsconfig = path.join(dir, 'tsconfig.json');
			const jsconfig = path.join(dir, 'jsconfig.json');

			if (fs.existsSync(tsconfig)) {
				config_filename = tsconfig;
				break;
			}

			if (fs.existsSync(jsconfig)) {
				config_filename = jsconfig;
				break;
			}
		}
	}

	if (!config_filename) {
		throw new Error('Failed to locate tsconfig or jsconfig');
	}

	const { error, config } = ts.readConfigFile(config_filename, ts.sys.readFile);

	if (error) {
		throw new Error('Malformed tsconfig\n' + JSON.stringify(error, null, 2));
	}

	// Do this so TS will not search for initial files which might take a while
	config.include = [];
	config.files = [];
	const { options } = ts.parseJsonConfigFileContent(
		config,
		ts.sys,
		path.dirname(config_filename),
		{ sourceMap: false },
		config_filename
	);

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Add a tsconfig.json (or at minimum a jsconfig.json) at the project root.
  2. In monorepos, add a minimal tsconfig.json to the packaged package even if it only extends the root config.
  3. Pass `--tsconfig <path>` explicitly to point at an existing config.

Example fix

// before: no tsconfig in project

// after: tsconfig.json at project root
{
  "extends": "../tsconfig.base.json",
  "include": ["src/**/*.ts", "src/**/*.svelte"]
}
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'node:fs';
if (!fs.existsSync('tsconfig.json') && !fs.existsSync('jsconfig.json')) {
  throw new Error('project needs a tsconfig.json or jsconfig.json');
}

Try / catch

try {
  await run(['svelte-package']);
} catch (e) {
  if (String(e.message).includes('Failed to locate tsconfig')) {
    throw new Error('Add a tsconfig.json at the project root (it may just extend a base config)');
  }
  throw e;
}

Prevention

When it happens

Trigger: Running svelte-package in a project with no tsconfig.json or jsconfig.json anywhere between the input directory and the filesystem root, while TS processing/types generation is required.

Common situations: JS library project that never created a jsconfig; repo where the config lives far outside the packaged package in a monorepo layout the traversal misses; config file accidentally deleted or gitignored.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/5955b2a7d4206598. Report an issue: GitHub.