FG
๐Ÿ› ๏ธ Developer ToolsMicrosoft

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

Freshabout 20 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] 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 [code block] 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 [code block]

Unverified for your environment

Select your OS to check compatibility.

2 Fixes

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Disable Experimental ES Module Support in Node.js

Medium Risk

The warning occurs because Node.js v23.0.0 has experimental support for loading ES Modules using require(), which is not fully stable. This feature may change in future releases, leading to the warning message when attempting to use it.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Set Node.js to use CommonJS modules

    To avoid the experimental warning, you can ensure that your project is using CommonJS modules instead of ES Modules. This can be done by renaming your JavaScript files from .mjs or .js (if using 'type': 'module' in package.json) to .cjs.

    bash
    mv yourModule.js yourModule.cjs
  2. 2

    Update package.json configuration

    If your project is set to use ES Modules, you can remove the 'type': 'module' line from your package.json file to revert to CommonJS. This will prevent Node.js from treating your files as ES Modules.

    json
    Remove 'type': 'module' from package.json
  3. 3

    Use dynamic import for ES Modules

    If you need to use ES Modules, consider using dynamic import syntax instead of require(). This will allow you to load ES Modules without triggering the experimental warning.

    javascript
    const module = await import('./yourModule.js');
  4. 4

    Check Node.js version compatibility

    Ensure that your code is compatible with the Node.js version you are using. If you need stable ES Module support, consider downgrading to a stable version of Node.js (e.g., v18.x.x) until the feature is fully supported.

    bash
    nvm install 18 && nvm use 18

Validation

Run your application again after applying the above steps. The warning should no longer appear. If you opted for dynamic imports, ensure that the modules load correctly without errors.

Sign in to verify this fix

1 low-confidence fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Disable Experimental ES Module Warning in Node.js

Medium Risk

The warning occurs because Node.js v23.0.0 is still in an experimental phase regarding ES Module support when using require(). This feature is not fully stable, and the warning indicates that it may change in future versions. The warning is intended to inform developers that they should be cautious when using this feature.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Set Node.js Environment Variable

    To suppress the experimental warning, you can set the NODE_OPTIONS environment variable to ignore the warning. This can be done in your terminal or command prompt before running your Node.js application.

    bash
    set NODE_OPTIONS=--no-warnings
  2. 2

    Update Your Codebase

    If possible, refactor your code to use ES Module syntax (import/export) instead of CommonJS (require/module.exports). This will help avoid the warning and future-proof your application.

    javascript
    import package from 'your-package';
  3. 3

    Check Node.js Version Compatibility

    Ensure that your Node.js version is compatible with the packages you are using. If the warning persists, consider downgrading to a stable version of Node.js (e.g., v18.x.x) until ES Module support is fully stable.

    bash
    nvm install 18
  4. 4

    Monitor Node.js Updates

    Keep an eye on Node.js release notes and updates for changes regarding ES Module support. This will help you adapt your application as the feature matures.

    none
    Visit https://nodejs.org/en/blog/release/

Validation

Run your Node.js application after setting the NODE_OPTIONS variable. The warning should no longer appear. Additionally, check your application functionality to ensure everything is working as expected. If you refactored to ES Modules, verify that imports and exports are functioning correctly.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsbugneeds-triage