TypeScript error

TS2880: assert on an import, where with is required

  • Error TS2880
  • Tested with TypeScript 5.9

Import assertions (assert { type: "json" }) were replaced in the JavaScript standard by import attributes (with { type: "json" }). Per the TypeScript 5.8 page, Node.js 22 no longer accepts assert, and under module: "nodenext" TypeScript reports it as TS2880.

The fix is one word, and the rest of the import stays as it is.

At a glance

CodeTS2880
MessageImport assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
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 message is TypeScript's own text from its diagnostic messages file (Apache-2.0).

What it looks like

main.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: main.js(2,36): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. main.js(2,36): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. main.js(2,36): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. checked 21 October 2026
import config from "./config.json" assert { type: "json" };error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.

export const port = config.port;
assert on a JSON import, under module nodenext.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["**/*.js"]
}

What causes it

  • Code written for Node.js 16 to 20, or copied from older documentation, that still says assert.

How to fix it

Write with instead of assert

import config from "./config.json" with { type: "json" }; is accepted by current Node.js versions and by TypeScript under every module setting that allows attributes.

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 port = config.port;
The same import with with.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["**/*.js"]
}

Gotchas

  • With module: "esnext" or "preserve", TypeScript 5.9 still accepts assert, so the error appears when a project moves to nodenext.
  • The same JSON import without any attribute is TS1543 under nodenext.

Sources

Last reviewed 21 October 2026.