Node.js v16 to v18
AugustinMauroy
Node.js v16 to v18
!
This article covers a part of the migration from Node.js v16 to v18. 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 v16 to v18.
err-invalid-callback
In Node.js v18, the DEP0159 deprecation was introduced, which deprecated the ERR_INVALID_CALLBACK error code in favor of ERR_INVALID_ARG_TYPE. This codemod will help you replace any references to the old error code with the new one.
The source code for this codemod can be found in the err-invalid-callback directory.
You can find this codemod in the Codemod Registry.
npx codemod run @nodejs/err-invalid-callbackExample:
try {
fs.readFile("file.txt", "invalid-callback");
} catch (err) {
- if (err.code === "ERR_INVALID_CALLBACK") {
+ if (err.code === "ERR_INVALID_ARG_TYPE") {
console.error("Invalid callback provided");
}
}Also handles deduplication when both codes were already checked:
const isCallbackError =
- err.code === "ERR_INVALID_CALLBACK" ||
- err.code === "ERR_INVALID_ARG_TYPE";
+ err.code === "ERR_INVALID_ARG_TYPE";