react/create-react-app · error · Error
ts.formatDiagnostic(error, formatDiagnosticHost)
Error message
ts.formatDiagnostic(error, formatDiagnosticHost)
What it means
verifyTypeScriptSetup reads tsconfig.json via ts.readConfigFile. If TypeScript itself reports an error reading the file (e.g. the file is missing, unreadable, or contains content readConfigFile flags as an error), that diagnostic is formatted into a string and thrown. This is the first of two tsconfig gates in the try block.
Source
Thrown at packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js:179
const formatDiagnosticHost = {
getCanonicalFileName: fileName => fileName,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => os.EOL,
};
const messages = [];
let appTsConfig;
let parsedTsConfig;
let parsedCompilerOptions;
try {
const { config: readTsConfig, error } = ts.readConfigFile(
paths.appTsConfig,
ts.sys.readFile
);
if (error) {
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(View on GitHub (pinned to 6254386531)
Solutions
- Ensure tsconfig.json exists at the project root and is readable.
- Validate the JSON syntax with a linter or `npx tsc --noEmit` to surface the exact diagnostic.
- If using `extends`, confirm the base config path resolves (e.g. tsconfig.json from react-scripts or a shared config exists).
- Restore tsconfig.json from version control if it was deleted.
Example fix
// before
tsconfig.json: { "extends": "./nonexistent/base.json", "compilerOptions": {} }
// after
tsconfig.json: { "extends": "react-scripts/tsconfig.json", "compilerOptions": {} } Defensive patterns
Strategy: try-catch
Validate before calling
const fs = require('fs');
const ts = require('typescript');
function preflightReadTsConfig(tsConfigPath) {
if (!fs.existsSync(tsConfigPath)) {
throw new Error(`tsconfig.json missing at ${tsConfigPath}`);
}
const { error } = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
if (error) {
throw new Error(ts.formatDiagnostic(error, formatHost));
}
}
preflightReadTsConfig(paths.appTsConfig); Type guard
const tsConfigReadsClean = (p) => {
const { error } = ts.readConfigFile(p, ts.sys.readFile);
return !error;
}; Try / catch
try {
require('react-scripts/scripts/utils/verifyTypeScriptSetup');
} catch (e) {
if (/tsconfig\.json|Could not parse/i.test(e.message)) {
console.error('tsconfig.json could not be read. Check syntax/exists/extends.');
process.exit(1);
}
throw e;
} Prevention
- Validate tsconfig.json with `npx tsc --noEmit` after edits.
- Confirm any `extends` target exists and is a valid config.
- Keep tsconfig.json under version control so deletions are visible.
- Use a JSON schema in your editor for tsconfig to catch typos.
When it happens
Trigger: Running tsc-based type checking (react-scripts build/test with TypeScript) when ts.readConfigFile returns a non-null `error` object for paths.appTsConfig. The `if (error)` branch formats the diagnostic and throws.
Common situations: tsconfig.json deleted or renamed after being referenced. File permissions prevent reading. A JSON syntax error that readConfigFile surfaces as a diagnostic. An invalid `extends` target that readConfigFile cannot resolve.
Related errors
- ts.formatDiagnostic(result.errors[0], 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/fa899ca5050a4275.
Report an issue: GitHub.