Desk Clarity

Everyday document & browser help

Node JSON Import Fails at Assert: Check Native ESM Import Attributes

By ON Lab · Sources checked November 8, 2026

In current Node.js native ES modules, importing JSON uses with { type: "json" }. An old assert { type: "json" } statement can fail to parse on Node 22 and later. First check the actual Node version and the file containing the import; changing your application file will not fix an old import inside a dependency’s configuration.

Find the parser and the file it is parsing

A bundler error may still originate in Node while loading the bundler’s configuration. The public Rollup report we inspected used Node 22.2.0, Rollup 4.18.0 and Ubuntu 24.04; its stack trace reported an unexpected assert identifier. That is evidence of a particular historical failure, not proof that every Rollup error has this cause.

Record node --version, the exact error, and the first relevant source filename. A syntax error at assert, an error saying an import attribute is missing, and a JSON parse error are different stages. Keep them separate before changing package versions.

Test native loading without the bundler

In a disposable directory, create data.json containing:

{"label":"sample"}

Then create read.mjs. The .mjs extension makes this a native ES module without changing a real project’s package settings.

import data from './data.json' with { type: 'json' };
console.log(data.label);

Run node read.mjs. On our Node 24.22.2 fixture, it printed sample. With the attribute omitted, the same JSON import failed with ERR_IMPORT_ATTRIBUTE_MISSING. Replacing with by the old static assert syntax failed with a syntax error.

Dynamic imports have an options boundary too

const { default: data } = await import('./data.json', {
  with: { type: 'json' }
});
console.log(data.label);

This printed sample in our current-runtime fixture. Using { assert: { type: 'json' } } as the dynamic options did not satisfy the current attribute requirement and failed. A static parse error and an ignored or unrecognized dynamic option can therefore produce different messages even when the migration issue is related.

JSON exports the object as default

The native JSON module exposes its imported value as a default export. Use the object’s property after import. The following is not an equivalent named-export form:

// Not a named-export interface for data.json:
import { label } from './data.json' with { type: 'json' };

That named import failed in our fixture. Replacing one import keyword while retaining an unsupported export assumption will not complete the repair. The minimal example checks both the loading syntax and the shape of the value your code receives.

Apply the result at the correct layer

Where the import livesUseful next action
Your own native .mjs fileUpdate its syntax for the supported runtime and rerun the isolated example.
Generated build outputInspect the producing compiler/bundler target. A hand edit will be overwritten.
A dependency or its configCheck that package’s current compatibility guidance and a supported release; do not silently patch shared installed files.
Browser codeVerify that environment’s module and media-type behavior separately. This Node test is not a browser test.

Node’s versioned documentation records the import-attribute transition and removal of import assertions. Older Node versions may accept different syntax or lack support for a newer form. Choose the project’s documented supported runtime rather than blindly changing a production version to make an isolated example pass.

When ordinary file reading is the intended contract

If the application needs to read fresh JSON as data rather than import it as a cached module, a file-read-and-parse design may fit better. That is a different lifecycle with its own path and error handling. Do not mix the two merely to silence a parser error. The separate ESM file-URL and filesystem-path check covers resolving local paths.

Method: current Node 24 documentation, a historical Rollup user report and six synthetic native Node 24.22.2 cases on macOS. No packages were installed and no Rollup, TypeScript, browser or production dependency build was reproduced. The guide does not claim a specific dependency upgrade fixes the original report.

Sources