sveltejs/kit · error · Error
Malformed tsconfig ${JSON.stringify(error, null, 2)}
Error message
Malformed tsconfig
${JSON.stringify(error, null, 2)} What it means
After locating the config file, `load_tsconfig` calls `ts.readConfigFile`, which reports syntax/JSON errors in its `error` result. The packager surfaces this as a 'Malformed tsconfig' error with the diagnostics JSON appended, since a broken config cannot be parsed for compiler options.
Source
Thrown at packages/package/src/typescript.js:290
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
);
for (const dir of traversed_dirs) {
cache.set(dir, options);
}
return options;View on GitHub (pinned to 03f1687fe6)
Solutions
- Read the diagnostics JSON in the message and fix the reported line/character in the tsconfig.
- Validate the file with `npx tsc -p <path> --noEmit` or an editor's JSONC linter.
- Remove merge conflict markers or restore the file from version control.
- Check for a BOM or encoding corruption; resave as clean UTF-8.
Example fix
// before (tsconfig.json)
{
"compilerOptions": {
"target": "ES2022" // <- malformed: unquoted trailing garbage
module: "ESNext",
}
}
// after
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext"
}
} Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs';
const src = fs.readFileSync('tsconfig.json', 'utf8').replace(/^\uFEFF/, '');
try { JSON.parse(src.replace(/\/\/.*$/gm, '').replace(/,\s*([}\]])/g, '$1')); } catch (e) { throw new Error('tsconfig.json has invalid syntax: ' + e.message); } Try / catch
try {
await run(['svelte-package']);
} catch (e) {
if (String(e.message).startsWith('Malformed tsconfig')) {
// message embeds ts diagnostics JSON — surface it verbatim
throw e;
}
throw e;
} Prevention
- Validate tsconfig with `npx tsc --noEmit` in CI
- Keep tsconfig syntax standard JSONC and lint it with an editor plugin
- Resolve merge conflicts in config files before building
When it happens
Trigger: tsconfig.json/jsconfig.json contains invalid JSONC — trailing commas in wrong places, unquoted keys, stray BOM/characters, comment or syntax typos that the TS parser rejects.
Common situations: Hand-edited tsconfig with a typo; merge conflict markers left in the file; JSON5/JSONC syntax not accepted by the TS parser; truncated config after a failed edit.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to locate provided tsconfig or jsconfig
- Failed to locate tsconfig or jsconfig
- Invalid alias key: ${key}
- Invalid alias value: ${value}
- ${path.relative(process.cwd(), user_config.file)} should ext
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/8cebd740da32b934.
Report an issue: GitHub.