-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
import(cjs) with query strings has odd behavior #29812
Comments
This issue is still valid in Node.js 13.0.1. |
Here is how CJS modules are loaded into the ESM loader:
As a result: CommonJS modules loaded with query strings will not load their exports, AND query strings will not reload the module. This is the way the design works unfortunately and it cannot really be changed. It was done this way because it was deemed important to "snapshot" CommonJS modules at their time of execution to inject them into the ESM loader. The only way to allow the model this issue is asking for would be to remove that "snapshot" requirement, which I'm not sure is possible. That said if it is possible - now would be the time to argue for it. |
Should this be closed as |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
From eslint/eslint#12333
Repro https://github.com/mysticatea/import-cjs-issue
Description
I tried to import packages without import cache. From the document, it looks I should use query strings.
x-esm
is an ES module package. It worked as expected.x-cjs
is a CJS package. The result was odd. Theconsole.log()
inx-cjs
package ran only one time, but the returned values are different for each query string.I found the entry of
x-cjs
inrequire.cache
. However, the cache entry is odd as well. It's different fromrequire("x-cjs")
, the entry doesn't haveparent
property and themodule.children
oftest.js
is still empty.Anyway, I tried to remove the cache entry.
Cryptic. I guess this behavior is:
import(cjs)
has cache apart fromrequire.cache
.import(cjs)
cache is created fromrequire.cache
.require.cache
entry was not found.import(cjs)
cache is not removed even ifrequire.cache
entry deleted.Therefore, I have to do the following steps if I want to import packages without cache.
require.cache
entry.Questions
import(cjs)
creates incompleterequire.cache
entries?import(cjs)
with query strings returns different objects for the same CJS package?I'm guessing that
import(cjs)
should not create anyrequire.cache
entries, andimport(cjs)
with query strings re-runs CJS packages as same as ES packages.The text was updated successfully, but these errors were encountered: