parcel-bundler/parcel · error · ThrowableDiagnostic
Error parsing ${path.relative(this.options.inputFS.cwd(), pk
Error message
Error parsing ${path.relative(this.options.inputFS.cwd(), pkgFile)}: ${err.message} What it means
Thrown by readPackage() when JSON.parse(content) fails on a package.json file that was successfully read from disk. The error includes the relative path to the package.json and the underlying JSON parse error message.
Source
Thrown at packages/core/core/src/requests/EntryRequest.js:369
async readPackage(entry: FilePath): Promise<?{
...PackageJSON,
filePath: FilePath,
map: {|data: mixed, pointers: {|[string]: Mapping|}|},
...
}> {
let content, pkg;
let pkgFile = path.join(entry, 'package.json');
try {
content = await this.options.inputFS.readFile(pkgFile, 'utf8');
} catch (err) {
return null;
}
try {
pkg = JSON.parse(content);
} catch (err) {
// TODO: code frame?
throw new ThrowableDiagnostic({
diagnostic: {
message: md`Error parsing ${path.relative(
this.options.inputFS.cwd(),
pkgFile,
)}: ${err.message}`,
},
});
}
return {
...pkg,
filePath: pkgFile,
map: parse(content, undefined, {tabWidth: 1}),
};
}
}
View on GitHub (pinned to 59484858a1)
Solutions
- Validate the package.json with a JSON linter: npx jsonlint package.json or use your editor's JSON validation.
- Look for the specific parse error in the message (line/column) and fix that exact location.
- Remove trailing commas, ensure all keys are double-quoted, and remove comments.
- If package.json was corrupted by a merge conflict, resolve the conflict markers first.
- Use a JSON formatter/prettier to auto-fix structural issues: npx prettier --write package.json.
Example fix
// before — package.json (invalid)
{
"name": "app",
"source": "index.html",
}
// after
{
"name": "app",
"source": "index.html"
} Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
function validatePackageJson(pkgPath) {
const content = fs.readFileSync(pkgPath, 'utf8');
try {
JSON.parse(content);
} catch (e) {
throw new Error(`Invalid JSON in ${pkgPath}: ${e.message}`);
}
} Prevention
- Use an editor with JSON validation/syntax checking.
- Run npx jsonlint package.json in CI or as a precommit hook.
- Avoid hand-editing large package.json — use npm/pkg commands which preserve validity.
When it happens
Trigger: Called from resolveEntry() when the entry is a directory. readPackage() reads <entry>/package.json, and if JSON.parse(content) throws (SyntaxError), the ThrowableDiagnostic is raised with err.message (e.g., 'Unexpected token').
Common situations: Hand-editing package.json and leaving a trailing comma, unquoted key, or missing brace; JSON5-only syntax (comments, unquoted keys) in a file parsed as strict JSON; copy-paste introducing smart quotes or invisible characters; truncated file from a git merge conflict.
Related errors
- Failed to parse package.json
- ${path.relative(process.cwd(), source)} does not exist.
- ${path.relative(process.cwd(), source)} is not a file.
- Could not find entry: ${entry}
- Failed to parse .parcelrc
AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13).
Data as JSON: /api/errors/d3c405aeee910a34.
Report an issue: GitHub.