From 0a21f300e8abc3a3b97d687a70a81190eb7e60ee Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 9 Dec 2024 15:47:25 +0100 Subject: [PATCH] module: only emit require(esm) warning under --trace-require-module require(esm) is relatively stable now and the experimental warning has run its course - it's now more troublesome than useful. This patch changes it to no longer emit a warning unless `--trace-require-module` is explicitly used. The flag supports two modes: - `--trace-require-module=all`: emit warnings for all usages - `--trace-require-module=no-node-modules`: emit warnings for usages that do not come from a `node_modules` folder. PR-URL: https://github.com/nodejs/node/pull/56194 Fixes: https://github.com/nodejs/node/issues/55417 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Yagiz Nizipli Reviewed-By: Matteo Collina Reviewed-By: Geoffrey Booth Reviewed-By: Marco Ippolito Reviewed-By: Rafael Gonzaga --- doc/api/cli.md | 13 +++++++++ doc/api/modules.md | 14 ++++++--- lib/internal/modules/cjs/loader.js | 29 +++++++++++-------- src/node_options.cc | 13 +++++++++ src/node_options.h | 1 + test/es-module/test-require-module-preload.js | 11 ------- test/es-module/test-require-module-warning.js | 14 +++++++-- test/es-module/test-require-module.js | 10 ------- .../test-require-node-modules-warning.js | 24 +++++++++++---- test/es-module/test-typescript-commonjs.mjs | 1 - test/es-module/test-typescript.mjs | 2 -- 11 files changed, 83 insertions(+), 49 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 321d2b9ec130ea..154cbc9401d5ca 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2669,6 +2669,18 @@ added: Prints a stack trace whenever an environment is exited proactively, i.e. invoking `process.exit()`. +### `--trace-require-module=mode` + + + +Prints information about usage of [Loading ECMAScript modules using `require()`][]. + +When `mode` is `all`, all usage is printed. When `mode` is `no-node-modules`, usage +from the `node_modules` folder is excluded. + ### `--trace-sigint`