From 7987ae59e46acb03d488595256d8609edbb83fa0 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 | 15 +++++++--- 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 +++++++++++---- 9 files changed, 84 insertions(+), 46 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 88c961b99a0a42f..2fd8a5bc01202ff 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2387,6 +2387,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`