Skip to content
Latchkey

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.

node
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+).

index.js
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.

index.js
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.parse for broad compatibility.

Frequently asked questions

What causes ""ERR_IMPORT_ATTRIBUTE_MISSING""?
ESM requires with { type: "json" } (the import attributes syntax) to load JSON modules.
How do I fix "ERR_IMPORT_ATTRIBUTE_MISSING"?
Use the with { type: "json" } attribute on the JSON import (Node 20.10+ / 22+).

Related guides

References

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