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

  1. Validate the package.json with a JSON linter: npx jsonlint package.json or use your editor's JSON validation.
  2. Look for the specific parse error in the message (line/column) and fix that exact location.
  3. Remove trailing commas, ensure all keys are double-quoted, and remove comments.
  4. If package.json was corrupted by a merge conflict, resolve the conflict markers first.
  5. 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

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


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