Skip to content
Latchkey

Eleventy "data file could not be parsed" in CI

Eleventy loads every file under the data directory to build the global data cascade. A data file with invalid JSON, or a JS data file that throws on import, stops the whole build.

What this error means

eleventy build fails referencing a file in _data, with a JSON parse error or an exception thrown from the module, before templates render.

eleventy
[11ty] Error: Data file './src/_data/site.json' could not be parsed.
[11ty]   SyntaxError: Unexpected token } in JSON at position 142

Common causes

Invalid JSON in a data file

A trailing comma or unquoted key makes a _data/*.json file fail to parse.

A JS data file that throws on load

A _data/*.js module reads an env var or fetches at import; when that is unset or fails in CI, the export throws.

How to fix it

Validate the JSON data file

  1. Open the named file at the reported position.
  2. Remove trailing commas and quote all keys.
  3. Validate it parses, then re-run the build.
Terminal
node -e "JSON.parse(require('fs').readFileSync('src/_data/site.json','utf8'))"

Make JS data resilient in CI

Default missing env vars and handle fetch failures so the module exports cleanly during the build.

src/_data/items.js
export default async function () {
  const url = process.env.API_URL;
  if (!url) return { items: [] };
  // ... fetch and return
}

How to prevent it

  • Validate JSON data files before committing.
  • Default env-dependent JS data so CI never throws on load.
  • Keep data files small and free of side effects.

Frequently asked questions

What causes ""data file could not be parsed""?
A trailing comma or unquoted key makes a _data/*.json file fail to parse.
How do I fix "data file could not be parsed"?
Validate the JSON data file

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card