{"record":{"id":"8cebd740da32b934","repo":"sveltejs/kit","slug":"malformed-tsconfig-json-stringify-error-null-2","errorCode":null,"errorMessage":"Malformed tsconfig\n${JSON.stringify(error, null, 2)}","messagePattern":"Malformed tsconfig\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/package/src/typescript.js","lineNumber":290,"sourceCode":"\t\t\t\tconfig_filename = tsconfig;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (fs.existsSync(jsconfig)) {\n\t\t\t\tconfig_filename = jsconfig;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!config_filename) {\n\t\tthrow new Error('Failed to locate tsconfig or jsconfig');\n\t}\n\n\tconst { error, config } = ts.readConfigFile(config_filename, ts.sys.readFile);\n\n\tif (error) {\n\t\tthrow new Error('Malformed tsconfig\\n' + JSON.stringify(error, null, 2));\n\t}\n\n\t// Do this so TS will not search for initial files which might take a while\n\tconfig.include = [];\n\tconfig.files = [];\n\tconst { options } = ts.parseJsonConfigFileContent(\n\t\tconfig,\n\t\tts.sys,\n\t\tpath.dirname(config_filename),\n\t\t{ sourceMap: false },\n\t\tconfig_filename\n\t);\n\n\tfor (const dir of traversed_dirs) {\n\t\tcache.set(dir, options);\n\t}\n\n\treturn options;","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/package/src/typescript.js#L272-L308","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (tsconfig.json)\n{\n  \"compilerOptions\": {\n    \"target\": \"ES2022\" // <- malformed: unquoted trailing garbage\n    module: \"ESNext\",\n  }\n}\n\n// after\n{\n  \"compilerOptions\": {\n    \"target\": \"ES2022\",\n    \"module\": \"ESNext\"\n  }\n}","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nconst src = fs.readFileSync('tsconfig.json', 'utf8').replace(/^\\uFEFF/, '');\ntry { JSON.parse(src.replace(/\\/\\/.*$/gm, '').replace(/,\\s*([}\\]])/g, '$1')); } catch (e) { throw new Error('tsconfig.json has invalid syntax: ' + e.message); }","typeGuard":null,"tryCatchPattern":"try {\n  await run(['svelte-package']);\n} catch (e) {\n  if (String(e.message).startsWith('Malformed tsconfig')) {\n    // message embeds ts diagnostics JSON — surface it verbatim\n    throw e;\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["typescript","tsconfig","json","parse-error","configuration"],"backgroundTag":"tsconfig-parse-error","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}