Node "ERR_IMPORT_ATTRIBUTE_MISSING" importing JSON in CI
Importing a JSON file from ESM requires an explicit type attribute. Without with { type: "json" }, Node throws because it will not infer the JSON module type from the extension alone.
What this error means
A JSON import fails with "TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]" (newer Node) or "ERR_IMPORT_ASSERTION_TYPE_MISSING" (older Node) naming the JSON specifier.
import data from './config.json';
^
TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "file:///app/config.json" needs an
import attribute of "type: json"Common causes
JSON imported without the type attribute
ESM requires with { type: "json" } (the import attributes syntax) to load JSON modules.
Old import assertion syntax on newer Node
The earlier assert { type: "json" } syntax was replaced by with; mixing versions can surface the missing-attribute error.
How to fix it
Add the import attribute
Use the with { type: "json" } attribute on the JSON import (Node 20.10+ / 22+).
import data from './config.json' with { type: 'json' };Or read JSON without an import
Avoid the attribute entirely by reading and parsing the file at run time.
import { readFile } from 'node:fs/promises';
const data = JSON.parse(await readFile(new URL('./config.json', import.meta.url), 'utf8'));How to prevent it
- Use
with { type: "json" }for ESM JSON imports. - Match attribute syntax to the Node version your runners use.
- Prefer
fs.readFile+JSON.parsefor broad compatibility.