Urgent.News

What's breaking now, across thousands of outlets.

Tech

NestJS 12: ESM Packages, Standard Schema Validation and Native Observability

NestJS version 12 has been released, transitioning core packages to ESM and adding Standard Schema validation. It updates the CLI and introduces an observability SDK. Key changes include project generation choices between CJS and ESM, improved validation options, and lifecycle project hooks. Users will need Node.js 20.19+ or 22.12+. Migration guides are available for upgrading. By Daniel Curtis

NestJS 12, the latest major release of the TypeScript framework for building server-side Node.js applications, has been officially announced. This update marks a significant shift towards ESM (ECMAScript Modules) packages, introduces standard schema validation, revamps the CLI, and presents an official observability SDK. The decision to adopt ESM is largely welcomed due to its minimal impact on existing teams, who can still use CommonJS applications by leveraging Node.js require(esm) support.

The minimum Node.js version required for v12 is 20.19 or 22.12. The framework's CLI now prompts users to choose between CommonJS (CJS) or ESM projects during initialization, with ESM projects defaulting to Vitest and oxlint. The transition to Vitest and oxlint replaces webpack as the monorepo bundler. The most notable change in terms of developer ergonomics is the introduction of standard schema validation, where route decorators like @Body(), @Query() and @Param() can accept a schema option that accepts any Standard Schema compatible object, such as Zod, Valibot and ArkType.

While class-validator remains the documented default, NestJS continues to rely on legacy TypeScript decorators for type annotations. The most controversial addition is the @nestjs/observe module, which hooks into Nest's lifecycle through a new instrument option instead of patching the HTTP server. This module reports traces in terms of controllers and providers, offering richer context to APM vendors, though it's worth noting that the SDK is NestJS-only, lacks cross-stack correlation out of the box and may lead to vendor lock-in at the framework level.

Another important feature is the nest deploy command, which forwards to the Mau platform, signaling a move towards first-party services. When upgrading from version 11 to 12, developers are advised to install the latest CLI using npm i -g @nestjs/cli@latest and run nest upgrade, which moves every @nestjs/* package to v12, bumps TypeScript to v6 and applies mechanical changes, such as switching the GraphQL Playground to GraphiQL and the NATS v3 client swap.

Notably, this migration does not convert projects to ESM, Vitest or oxlint. The upgrade guide covers additional changes, including lifecycle hook ordering and Joi v18. A GitHub issue prompted a note about AWS Lambda runtimes needing --experimental-require-module, while path aliases breaking under ESM and Fastify middleware exceptions hanging were also reported.

NestJS, an open-source, MIT-licensed framework, is known for its efficient and scalable server-side application building with TypeScript, combining Angular-inspired module and dependency injection architecture with Express and Fastify support.

Written by urgent.news from InfoQ's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at infoq.com →

More in Tech

More from Monday 19 October →