Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(react-scripts): support JSON with comments in jsconfig.json (#7426)
  • Loading branch information
DipakHalkude committed Sep 23, 2025
commit 25801073b8e10bce5ebbdd718ee92823c4adf688
34 changes: 33 additions & 1 deletion packages/react-scripts/config/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,39 @@ function getModules() {
// Otherwise we'll check if there is jsconfig.json
// for non TS projects.
} else if (hasJsConfig) {
config = require(paths.appJsConfig);
// Prefer using TypeScript parser to support JSON with comments in jsconfig.json
let ts;
try {
ts = require(
resolve.sync('typescript', {
basedir: paths.appNodeModules,
})
);
} catch (e) {
ts = null;
}

if (ts) {
// Use TypeScript's tolerant JSON parser which supports comments (JSONC)
config = ts.readConfigFile(paths.appJsConfig, ts.sys.readFile).config;
} else {
// Fallback: parse as strict JSON and provide actionable error for JSONC
try {
const fileContent = fs.readFileSync(paths.appJsConfig, 'utf8');
config = JSON.parse(fileContent);
} catch (e) {
throw new Error(
chalk.red.bold(
'Failed to parse jsconfig.json.\n' +
'If your jsconfig.json contains comments, please install TypeScript in your project:\n' +
' npm install --save-dev typescript\n' +
'or\n' +
' yarn add --dev typescript\n' +
'Create React App will then parse jsconfig.json with comment support.'
)
);
}
}
}

config = config || {};
Expand Down