Node.js v20 to v22

AugustinMauroy

Node.js v20 to v22

!

This article cover a part of the migration from Node.js v20 to v22. The userland migrations team is working on more codemods to help you with the migration.

This page provides a list of codemods to help you migrate your code from Node.js v20 to v22.

import-assertions-to-attributes

During the process of TC39 standardization, the import assert feature was introduced to allow importing JSON modules but during the during the transition to stage 4, the assert keyword was removed and replaced with an with attribute on the import statement.

So in node.js v22, the import assert feature was removed and you need to use the with attribute instead.

Also note that the with keyword as been introduce in node.js v18.20 but it was not mandatory until v22.

npx codemod run @nodejs/import-assertions-to-attributes

Example:

import jsonData from './data.json' assert { type: 'json' };

Source Code

The source code for this codemod can be found in the import-assertions-to-attributes directory.

You can find this codemod in the Codemod Registry.

Última Actualización
10 oct 2025
Tiempo de Lectura
1 min
Contribuir
Editar esta página
Tabla de Contenidos
  1. import-assertions-to-attributes
  2. Example:
  3. Source Code
  4. Registry Link