parcel-bundler/parcel · error · ThrowableDiagnostic

Failed to parse .parcelrc

Error message

Failed to parse .parcelrc

What it means

Thrown by parseAndProcessConfig() when the JSON5 parse of .parcelrc contents fails. The error includes a code frame with the exact line and column from the parse exception (e.lineNumber / e.columnNumber) and the escaped parse error message.

Source

Thrown at packages/core/core/src/requests/ParcelConfigRequest.js:226

): Promise<ParcelConfigChain> {
  return processConfigChain(config, config.filePath, options);
}

// eslint-disable-next-line require-await
export async function parseAndProcessConfig(
  configPath: FilePath,
  contents: string,
  options: ParcelOptions,
): Promise<ParcelConfigChain> {
  let config: RawParcelConfig;
  try {
    config = parse(contents);
  } catch (e) {
    let pos = {
      line: e.lineNumber,
      column: e.columnNumber,
    };
    throw new ThrowableDiagnostic({
      diagnostic: {
        message: `Failed to parse .parcelrc`,
        origin: '@parcel/core',

        codeFrames: [
          {
            filePath: configPath,
            language: 'json5',
            code: contents,
            codeHighlights: [
              {
                start: pos,
                end: pos,
                message: escapeMarkdown(e.message),
              },
            ],
          },
        ],

View on GitHub (pinned to 59484858a1)

Solutions

  1. Use the line/column in the diagnostic to jump to the exact error location.
  2. Validate the file as JSON5: npx json5 .parcelrc (parses and reports errors).
  3. Check for unclosed braces/brackets and stray trailing commas.
  4. Start from a known-good config: { "extends": "@parcel/config-default" } and add customizations incrementally.
  5. Use an editor with JSON5 syntax highlighting to catch errors visually.

Example fix

// before — .parcelrc (broken)
{
  "extends": "@parcel/config-default"
  "transformers": { "*.css": [...] }
}

// after
{
  "extends": "@parcel/config-default",
  "transformers": { "*.css": [...] }
}
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const JSON5 = require('json5');
function validateParcelrcSyntax(parcelrcPath) {
  const content = fs.readFileSync(parcelrcPath, 'utf8');
  try {
    JSON5.parse(content);
  } catch (e) {
    throw new Error(`Syntax error in ${parcelrcPath} at line ${e.lineNumber}: ${e.message}`);
  }
}

Prevention

When it happens

Trigger: Called during config chain processing. parse(contents) (JSON5 parser) throws on malformed syntax — unclosed braces, stray commas, invalid tokens. The catch block extracts line/column from the exception and builds a precise code-frame diagnostic.

Common situations: Hand-editing .parcelrc and introducing a syntax error; copy-pasting a config fragment with wrong quoting; missing closing brace/bracket; using YAML or JS-style comments in what should be JSON5; encoding issues (BOM, CRLF in some edge cases).

Understand the failure class

Related errors


AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13). Data as JSON: /api/errors/72f510a0248756d2. Report an issue: GitHub.