From 9863d2756623f09dc7af5b01f5bded36d7b6d3ae 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 | 11 +++++-- lib/internal/modules/cjs/loader.js | 29 +++++++++++-------- src/node_options.cc | 12 ++++++++ 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, 80 insertions(+), 48 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 8a4f376360008f..7d22f746860b89 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2613,6 +2613,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`