An import attribute is a key-value pair attached to a module request, written after the specifier with the with keyword. The host (browser, Node.js) uses it to decide how to load the module. The only standard key is type; JSON modules, type: 'json', are part of ECMAScript.
import config from './config.json' with { type: 'json' };
const { default: config2 } = await import('./config.json', { with: { type: 'json' } });
Rules:
- Values are string literals. Attributes are part of the module request, next to the specifier.
- Unsupported keys fail. The spec makes a static
importwith an unsupported attribute aSyntaxErrorraised during loading (Node.js 24 reportsTypeError [ERR_IMPORT_ATTRIBUTE_UNSUPPORTED]). Inimport(), the promise rejects withTypeError. - JSON needs the attribute. The spec requires hosts to treat
type: 'json'as "parse this as JSON", and browsers and Node.js refuse to load JSON without it, so a server can't swap data for executable code. Without it Node.js throwsERR_IMPORT_ATTRIBUTE_MISSING. - A JSON module has one export. The parsed value is the
defaultexport (the spec'sParseJSONModulecreates a module with onlydefault). There are no named exports:import { name } from './x.json'is aSyntaxError. - One value per module. The module is evaluated once, so every importer gets the same object, and mutations are visible to all.
History: an earlier version of the proposal used assert { type: 'json' } ("import assertions"). MDN now lists assert as non-standard, and Node.js 24 rejects it (SyntaxError: Unexpected identifier 'assert').