Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time #7857

Open
2 tasks done
Tracked by #7860
alexsch01 opened this issue Oct 18, 2024 · 7 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps

Comments

@alexsch01
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When installing any package with Node.js v23.0.0 and npm v10.9.0, I get the following warning

(node:10424) 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)

Expected Behavior

No response

Steps To Reproduce

No response

Environment

  • npm: 10.9.0
  • Node.js: 23.0.0
  • OS Name: Windows 10 22H2
  • npm config: default
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v23.0.0
; npm local prefix = C:\Users\$USER\Downloads\test
; npm version = 10.9.0
; cwd = C:\Users\$USER\Downloads\test
; HOME = C:\Users\$USER
; Run `npm config ls -l` to show all defaults.
@alexsch01 alexsch01 added Bug thing that needs fixing Needs Triage needs review for next steps labels Oct 18, 2024
@shadowspawn
Copy link
Contributor

This is triggered by the experimental --experimental-require-module flag being made the default behaviour in Node.js 23. Related links:

@doni108108doni doni108108doni mentioned this issue Oct 19, 2024
2 tasks
@MikeMcC399
Copy link
Contributor

It's not necessary to install anything with npm to provoke the ExperimentalWarning.

For example, even with no npm modules installed, executing npm view npm version results in the ExperimentalWarning:

$ npm view npm version
(node:5212) 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)
10.9.0

Ubuntu 24.04.1 LTS
Node.js v23.0.0
npm 10.9.0 (latest)

Same ExperimentalWarning for many other CLI commands from https://docs.npmjs.com/cli/v10/commands:

npm audit
npm ci
npm doctor
npm init
npm install
npm install-ci-test
npm ls
npm outdated
npm prune
npm repo
npm show
... etc

@MikeMcC399
Copy link
Contributor

@MikeMcC399
Copy link
Contributor

Setting the environment variable NODE_OPTIONS='--trace-warnings' produces some trace output.

$ NODE_OPTIONS='--trace-warnings' npm view npm view
(node:6610) ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time
    at emitExperimentalWarning (node:internal/util:273:11)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1388:5)
    at Module._compile (node:internal/modules/cjs/loader:1525:5)
    at Object..js (node:internal/modules/cjs/loader:1680:16)
    at Module.load (node:internal/modules/cjs/loader:1328:32)
    at Function._load (node:internal/modules/cjs/loader:1138:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1350:12)
    at require (node:internal/modules/helpers:138:16)

@RedYetiDev
Copy link

FYI the ESM being require()d is supports-color.

@MikeMcC399
Copy link
Contributor

@RedYetiDev

FYI the ESM being require()d is supports-color.

You're right!

"supports-color": "^9.4.0",

where [email protected] and above is pure ESM

const supportsColor = require('supports-color'); 

where debug is effectively allowing an ESM version of supports-color to be installed and used:

  "peerDependenciesMeta": {
    "supports-color": {
      "optional": true
    }

So I guess the underlying issue debug-js/debug#975 needs to be resolved by debug.

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Oct 19, 2024

npm install [email protected] -g

and there was no more warning under Node.js v23.0.0 from

npm view npm version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps
Projects
None yet
Development

No branches or pull requests

4 participants