Node.js loads a JSON file from an ES module only with an import attribute: import config from "./config.json" with { type: "json" };. Under module: "nodenext", TypeScript holds JavaScript to the same rule and reports a JSON import without the attribute as TS1543.
Node.js also gives a JSON module a default export only, so a named import (import { port } from "./config.json") is TS1544 even with the attribute. Both checks arrived with TypeScript 5.7, per its release notes.
At a glance
| Code | TS1543 |
|---|---|
| Message | Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to '{0}'. |
Also on this page: TS1544 | Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to '{0}'. |
| TypeScript's category | error |
| Listed under | Modules and imports |
| Depends on | module |
| In .js files | Reported when the file is checked: checkJs in jsconfig.json, or // @ts-check at the top of the file |
The messages are TypeScript's own text from its diagnostic messages file (Apache-2.0); {0} is filled in by tsc for each error.
What it looks like
import config from "./config.json";error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'.
import { port } from "./config.json" with { type: "json" };error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'NodeNext'.
export const server = { port: config.port, fallback: port };jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["**/*.js"]
} What causes it
- A JSON import in an ES module (a
.mjsfile, or a.jsfile in a package with"type": "module") has nowith { type: "json" }. - A named import from a JSON file, which Node.js does not support.
How to fix it
Add the attribute and import the default
Write with { type: "json" } after the module name and read the values from the default export. TypeScript types the import from the file's contents.
import config from "./config.json" with { type: "json" };
export const server = { port: config.port };jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["**/*.js"]
} Gotchas
- CommonJS files load JSON with
require("./config.json")and need no attribute. - Bundlers and
moduleResolution: "bundler"do not require the attribute, so the error appears when a project moves tonodenextto match Node.js. - The older
assert { type: "json" }spelling is TS2880 undernodenext.
Sources
- TypeScript 5.7: checks for import attributes in nodenext · TypeScript handbook
- Modules: JSON modules · Node.js documentation
- diagnosticMessages.json (TypeScript 5.9.3) · TypeScript on GitHub
Last reviewed 21 October 2026.