Open ljharb opened 2 weeks ago
The warning can also be temporarily disabled using process.noDeprecation = true
(it's kind of an abuse because it's an experimental warning, not a deprecation warning, and it's kind of a bug that it affects the experimental warnings, but hey the bug is out there already). A slightly saner solution can be checking whether process.version
starts with v23 (the warning will be restricted to code not coming from node_modules on v22, and will probably be gone by 24).
supports-color@9.0.0, released in Apr 2021, was the first version to use pure ESM.
This issue affects any project where supports-color >= 9.0.0
(ESM only) is installed together with debug
. It is not restricted to npm
.
For instance, on Ubuntu 24.04.1
LTS, Node.js 23.0.0
, npm 10.9.0
, executing the following:
git clone https://github.com/cypress-io/github-action
cd github-action
npm ci
node src/ping-cli.js https://example.cypress.io
not only shows the ExperimentalWarning
from npm ci
, it also shows the warning from
node src/ping-cli.js https://example.cypress.io
which is not using npm
at all:
$ node src/ping-cli.js https://example.cypress.io
pinging url https://example.cypress.io for 30 seconds
(node:5900) ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
https://github.com/cypress-io/github-action is configured with supports-color@9.3.1, i.e. a pure ESM version.
@MikeMcC399 however, it'd only trigger on projects that require
that version, which virtually nobody would do, except in this package's case where it's treated like an implicit optional dep - requiring < 9, and importing any version, wouldn't trigger the warning.
Under Node.js v23.1.0
the warning provides additional debugging information which confirms the previous analysis:
$ npm view npm version
(node:13088) ExperimentalWarning: CommonJS module /home/mike/n/lib/node_modules/npm/node_modules/debug/src/node.js is loading ES Module /home/mike/n/lib/node_modules/npm/node_modules/supports-color/index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
10.9.0
Specifically, https://github.com/debug-js/debug/blob/bc60914816e5e45a5fff1cd638410438fc317521/src/node.js#L32 is triggering it. See also https://github.com/nodejs/node/pull/55338#issuecomment-2411753894 and https://github.com/nodejs/node/pull/55397.
I'm not sure the best solution here. One is to use optional peer deps to force
supports-color
to be< 9
; another is to do monkeypatching shenanigans around that require to suppress the experimental warning; I'm sure there's more.