Last active
October 6, 2023 04:17
-
-
Save o-az/fbac55d446603fee118b00c14cd35ef7 to your computer and use it in GitHub Desktop.
Suppress all Node.js warnings (including deprecation warnings)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { emit: originalEmit } = process; | |
/** | |
* @param {string} event | |
* @param {{ name: string; }} error | |
*/ | |
function suppresser(event, error) { | |
return event === "warning" && error.name === "ExperimentalWarning" | |
? false | |
: originalEmit.apply(process, arguments); | |
} | |
process.emit = suppresser; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use:
node --require="suppress-warnings.cjs" index.js
or with ts-node/tsx:
or set in
NODE_OPTIONS
environment variable:NODE_OPTIONS="--require=suppress-warnings.cjs" node index.js
Also works with
npm
/pnpm
/yarn
:NODE_OPTIONS="--require=suppress-warnings.cjs" pnpm run my-awesome-script
or, if you're on Node.js v19 or higher, rename to
suppress-warnings.mjs
and replace--require
with--import
in the command.