Skip to main content
This recipe transforms the usage of deprecated util._extend() to use Object.assign() to handle Node.js DEP0060.

What It Does

This codemod replaces:
  • util._extend() calls with Object.assign()
  • Removes unnecessary util imports when no longer needed

Before/After

Before:
const util = require("node:util");
const target = { a: 1 };
const source = { b: 2 };
const result = util._extend(target, source);
After:
const target = { a: 1 };
const source = { b: 2 };
const result = Object.assign(target, source);

Usage

Run this codemod on your project:
npx codemod node/userland/util-extend-to-object-assign
Object.assign() is the standard ECMAScript method for copying properties from one or more source objects to a target object. It’s more widely supported and follows JavaScript standards.
Both util._extend() and Object.assign() mutate the target object. If you need a non-mutating merge, use the spread operator: const result = { ...target, ...source }.

Build docs developers (and LLMs) love