From 4dde51d32b2e4951fc0e15098d74a3a0aa6e6fac Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 9 Dec 2024 15:47:25 +0100 Subject: [PATCH 1/2] 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. --- doc/api/cli.md | 13 +++++++++ doc/api/modules.md | 11 +++++-- 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, 81 insertions(+), 48 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 60140ab0864bd8..f71e58dac4e760 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2616,6 +2616,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`