[BUG] ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time
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
Disable Experimental ES Module Support in Node.js
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
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.
bashmv yourModule.js yourModule.cjs - 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.
jsonRemove 'type': 'module' from package.json - 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.
javascriptconst module = await import('./yourModule.js'); - 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.
bashnvm 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
Disable Experimental ES Module Warning in Node.js
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
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.
bashset NODE_OPTIONS=--no-warnings - 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.
javascriptimport package from 'your-package'; - 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.
bashnvm install 18 - 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.
noneVisit 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
Alex Chen
2450 rep