Skip to main content
This recipe transforms usage of the deprecated process.assert to the proper node:assert module.

Deprecation

Node.js deprecated process.assert in favor of the dedicated node:assert module. See DEP0100 for more details.

Usage

Run this codemod with:
npx codemod nodejs/process-assert-to-node-assert

Before/After

+ import assert from "node:assert";
- process.assert(condition, "Assertion failed");
+ assert(condition, "Assertion failed");

What It Does

  • Replaces process.assert() calls with assert() from node:assert
  • Automatically adds the appropriate import/require statement
  • Detects whether your project uses ESM or CommonJS by reading package.json
  • Preserves assertion arguments and error messages

Smart Import Detection

This codemod uses the fs capability to read your package.json file and determine if the project uses ES modules or CommonJS. Based on this information, it adds the appropriate import statement:
  • If "type": "module" is present, it adds: import assert from "node:assert";
  • Otherwise, it adds: const assert = require("node:assert");
The node:assert module provides a full suite of assertion functions including assert.strictEqual(), assert.deepEqual(), assert.throws(), and more.

Build docs developers (and LLMs) love