TypeScript error

TS1543: A JSON import without the import attribute

  • Error TS1543
  • Tested with TypeScript 5.9

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

CodeTS1543
MessageImporting 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 categoryerror
Listed underModules 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

main.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: main.js(2,20): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. main.js(4,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'NodeNext'. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. main.js(2,20): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. main.js(4,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'NodeNext'. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. main.js(2,20): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. main.js(4,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'NodeNext'. checked 21 October 2026
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 };
A JSON import from an ES module, without the import attribute.
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 .mjs file, or a .js file in a package with "type": "module") has no with { 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.

main.js TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
import config from "./config.json" with { type: "json" };

export const server = { port: config.port };
The default import, with with { type: "json" }.
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 to nodenext to match Node.js.
  • The older assert { type: "json" } spelling is TS2880 under nodenext.

Sources

Last reviewed 21 October 2026.