react/create-react-app · error · Error
ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)
Error message
ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)
What it means
After reading tsconfig.json, verifyTypeScriptSetup calls ts.parseJsonConfigFileContent to resolve extends/include/exclude and compilerOptions. If that returns any errors (e.g. invalid compiler option, unresolvable path, bad include glob), the first error is formatted and thrown. This is the second, deeper tsconfig gate.
Source
Thrown at packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js:197
throw new Error(ts.formatDiagnostic(error, formatDiagnosticHost));
}
appTsConfig = readTsConfig;
// Get TS to parse and resolve any "extends"
// Calling this function also mutates the tsconfig above,
// adding in "include" and "exclude", but the compilerOptions remain untouched
let result;
parsedTsConfig = immer(readTsConfig, config => {
result = ts.parseJsonConfigFileContent(
config,
ts.sys,
path.dirname(paths.appTsConfig)
);
});
if (result.errors && result.errors.length) {
throw new Error(
ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)
);
}
parsedCompilerOptions = result.options;
} catch (e) {
if (e && e.name === 'SyntaxError') {
console.error(
chalk.red.bold(
'Could not parse',
chalk.cyan('tsconfig.json') + '.',
'Please make sure it contains syntactically correct JSON.'
)
);
}
console.log(e && e.message ? `${e.message}` : '');
process.exit(1);View on GitHub (pinned to 6254386531)
Solutions
- Run `npx tsc --noEmit` to see the full list of config errors and address the first one.
- If you added `paths`, ensure `baseUrl` is set (CRA supports `src`).
- Check every compilerOptions key against the TypeScript reference for your TS version; remove/fix unknown ones.
- Verify `include`/`exclude` glob patterns point to existing directories.
- Simplify by removing `extends` temporarily to isolate whether the error comes from the base config.
Example fix
// before (tsconfig.json)
{
"compilerOptions": { "target": "esnextt", "paths": { "@/*": ["src/*"] } }
}
// after
{
"compilerOptions": { "target": "esnext", "baseUrl": "src", "paths": { "@/*": ["./*"] } }
} Defensive patterns
Strategy: try-catch
Validate before calling
const ts = require('typescript');
function preflightParseTsConfig(tsConfigPath) {
const { config } = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
const result = ts.parseJsonConfigFileContent(
config, ts.sys, require('path').dirname(tsConfigPath)
);
if (result.errors && result.errors.length) {
throw new Error(ts.formatDiagnostic(result.errors[0], formatHost));
}
}
preflightParseTsConfig(paths.appTsConfig); Type guard
const tsConfigParsesClean = (p) => {
const { config } = ts.readConfigFile(p, ts.sys.readFile);
const { errors } = ts.parseJsonConfigFileContent(config, ts.sys, require('path').dirname(p));
return !errors || errors.length === 0;
}; Try / catch
try {
require('react-scripts/scripts/utils/verifyTypeScriptSetup');
} catch (e) {
if (/TS\d+|compilerOptions|cannot be found/i.test(e.message)) {
console.error('tsconfig.json has invalid compilerOptions. Run `npx tsc --noEmit`.');
process.exit(1);
}
throw e;
} Prevention
- Run `npx tsc --noEmit` locally to surface all config diagnostics before building.
- When adding `paths`, always set `baseUrl` (CRA supports 'src').
- Cross-check compilerOptions against the TS version you depend on.
- Introduce `extends` one step at a time to isolate bad inherited options.
When it happens
Trigger: tsconfig.json parses as JSON but its resolved content is invalid: an unknown compilerOptions key, an invalid `paths`/`baseUrl` combination, an unreachable `include`/`exclude` glob, or a circular/broken `extends`. result.errors is a non-empty array, so the throw fires.
Common situations: Hand-editing compilerOptions and introducing a typo (e.g. `target: esnextt`). Adding `paths` without `baseUrl`. Pointing `include` at a non-existent directory. Extending a config whose compilerOptions conflict. Upgrading TypeScript and using an option removed in the new version.
Related errors
- ts.formatDiagnostic(error, formatDiagnosticHost)
- Your project's `baseUrl` can only be set to `src` or `node_m
- You have both a tsconfig.json and a jsconfig.json. If you ar
- Preset react-app: '${name}' option must be a boolean.
- Preset react-app: '${name}' option must be a boolean.
AI-assisted analysis of react/create-react-app@6254386531 (2026-08-12).
Data as JSON: /api/errors/eb8f4ca531e81972.
Report an issue: GitHub.