parcel-bundler/parcel · error · ThrowableDiagnostic
Failed to parse ${path.basename(configFile)}
Error message
Failed to parse ${path.basename(configFile)} What it means
Thrown by @parcel/utils readConfig when a JSON/JSON5 config file fails to parse. Only raised for files with a .json extension or no extension (JSON5-style files); other extensions rethrow the original parser error unwrapped. The ThrowableDiagnostic includes a code frame pinpointing e.lineNumber/e.columnNumber.
Source
Thrown at packages/core/utils/src/config.js:134
let config;
if (parse === false) {
config = configContent;
} else {
let extname = path.extname(configFile).slice(1);
let parse = opts?.parser ?? getParser(extname);
try {
config = parse(configContent);
} catch (e) {
if (extname !== '' && extname !== 'json') {
throw e;
}
let pos = {
line: e.lineNumber,
column: e.columnNumber,
};
throw new ThrowableDiagnostic({
diagnostic: {
message: `Failed to parse ${path.basename(configFile)}`,
origin: '@parcel/utils',
codeFrames: [
{
language: 'json5',
filePath: configFile,
code: configContent,
codeHighlights: [
{
start: pos,
end: pos,
message: e.message,
},
],
},
],
},View on GitHub (pinned to 59484858a1)
Solutions
- Open the file named in the message and fix the syntax at the reported line/column.
- Validate the file with `node -e "JSON.parse(require('fs').readFileSync('FILE','utf8'))"` (for strict JSON).
- Rename to .json5 / .jsonc if you intentionally use comments/trailing commas and ensure the right parser is registered.
- Remove git merge conflict markers or BOM before re-running.
Example fix
// before — .eslintrc.json (invalid: trailing comma)
{
"extends": ["parcel"],
}
// after
{
"extends": ["parcel"]
} Defensive patterns
Strategy: validation
Validate before calling
// Validate a JSON config before passing it to Parcel.
const fs = require('fs');
function validateJsonConfig(file) {
const txt = fs.readFileSync(file, 'utf8');
try { JSON.parse(txt); }
catch (e) { throw new Error(`${file} is invalid JSON: ${e.message}`); }
} Try / catch
try {
const cfg = await readConfig(fs, configFile);
} catch (e) {
if (e?.diagnostic?.message?.startsWith('Failed to parse')) {
// surface the code frame, prompt user to fix the file
} else throw e;
} Prevention
- Lint JSON configs in CI with a JSON parser before build.
- Use .jsonc/.json5 explicitly when you need comments/trailing commas and register the matching parser.
- Add editor schema validation for .parcelrc/tsconfig etc.
When it happens
Trigger: Parcel loads a .parcelrc, .eslintrc, tsconfig.json, or other JSON config that contains a syntax error (trailing comma, unquoted key, single quotes, unclosed brace) and the registered parser throws.
Common situations: Hand-editing JSON and introducing a trailing comma or comment; copying JSON5 syntax into a strict .json file; BOM/encoding issues; git merge conflicts leaving conflict markers in the config.
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 parse .parcelrc
- Only one spread parameter can be included in a config pipeli
- Local plugins are not supported in Parcel config packages. P
- Could not determine version of ${pluginName} in ${path.relat
- Config result is not hashable because it contains non-serial
AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13).
Data as JSON: /api/errors/e669aa309c9aaebf.
Report an issue: GitHub.