피드로 돌아가기
Node.js v20 to v22
Node.js BlogNode.js Blog
Backend

Node.js가 v20에서 v22로 업그레이드하면서 import assert 문법을 import with 속성으로 변경

Node.js v20 to v22

2025년 10월 28일3intermediate

Context

TC39 표준화 과정에서 JSON 모듈 import를 위해 import assert 문법이 도입되었으나, stage 4 진행 중 assert 키워드가 with 속성으로 대체되었다.

Technical Solution

  • import assert 문법을 import with 속성으로 변경: JSON 모듈 import 시 import json from './file.json' with { type: 'json' } 형식으로 수정
  • Node.js v18.20부터 with 키워드 지원했으나 v22에서 필수화: assert 키워드가 완전히 제거됨
  • Codemod 도구 제공: Codemod Registry에서 import-assertions-to-attributes 디렉토리의 소스 코드를 통해 자동 마이그레이션 가능

Key Takeaway

Node.js 메이저 버전 업그레이드 시 TC39 표준화 변경사항을 추적하고, 커뮤니티 제공 codemod를 활용하면 대규모 코드베이스의 마이그레이션 작업을 자동화할 수 있다.


Node.js v20 이상을 사용하는 프로젝트에서 JSON import를 다루고 있다면, v22 마이그레이션 전에 Codemod Registry의 import-assertions-to-attributes 도구를 실행하여 assert 문법을 with 속성으로 일괄 변환하면 호환성 이슈를 사전에 제거할 수 있다.

원문 읽기