Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.2k
Open
Description
Version
v22.1.0
Platform
Darwin MAGIT00999.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:09:52 PDT 2024; root:xnu-10063.121.3~5/RELEASE_X86_64 x86_64
Subsystem
No response
What steps will reproduce the bug?
Prepare the 3 files:
// register.mjsimport{register}from'module'import{readFile}from'fs/promises'exportasyncfunctionload(url,context,nextLoad){constresult=awaitnextLoad(url,context)if(result.format==='commonjs'){// https://nodejs.org/api/module.html#:~:text=result.source%20%3F%3F%3D%20await%20readFile(new%20URL(result.responseURL%20%3F%3F%20url))%3Bresult.source??=awaitreadFile(newURL(result.responseURL??url))}returnresult}register('./register.mjs?'+Date.now(),import.meta.url)// test.jsrequire('./package.json')// package.json{}
Then execute:
>node --import ./register.mjs test.js(node:5296) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time(Use `node --trace-warnings ...` to show where the warning was created)
How often does it reproduce? Is there a required condition?
It happens only with:
result.source??=awaitreadFile(newURL(result.responseURL??url));
If it does not handle commonjs files like this, it won't happen.
What is the expected behavior? Why is that the expected behavior?
require(json_file)
in commonjs modules should not emit this warning.
What do you see instead?
It emits warning
(node:5296) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
Additional information
No response
Metadata
Metadata
Assignees
Labels
No labels