-
Notifications
You must be signed in to change notification settings - Fork 30k
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
access the imported packages cache like require.cache #45206
Comments
The ESM cache is not exposed, and I believe this is per spec.
In this case, you may like the following:
globalThis.loadedURLs = [];
export function load(url, context, next) {
globalThis.loadedURLs.push(url);
return next(url, context);
}
const tester = import("./test.js");
import * as fs from "fs";
import console from 'console';
if (globalThis.loadedURLs) {
for (let p of globalThis.loadedURLs) {
console.log(p);
// console.log(trim(p));
}
} If you run I'm going to close this as I believe there's no bug to fix, but feel free to continue the discussion and ask more questions. |
i have one more question. while this is a hack, does this help in i am currently using a
https://github.com/ganeshkbhat/get-imports/blob/main/index.js do you think it is wise to add this hack in the docs? it may help a lot of people with unnecessary "..." across comments. like https://stackoverflow.com/questions/74216420/access-the-imported-packages-and-modules-cache-like-require-cache |
however, on a second, i believe this is a real opportunity area of exposing the |
@aduh95 Seems like the hack of loaders is not somehow working. |
You are more likely to get better results using a JS parser, such as acorn, otherwise you would have false positive (e.g. import statements in strings, in comments, etc.) and if the spec changes the syntax you would have to rethink your regex.
I don't see we could do that, AFAIK it's not something we have access to, making a request to the TC39 would indeed be the way to go, however I'd be surprised if it hasn't been discussed before.
What is not working? What command are you using? What output do you see? What were you expecting to get instead? |
I am looking at this. https://tc39.es/process-document/ what recommendations do you have for this. I probably need help to address the nodejs part of it. I would like if I have some subject matter exertise from you here. |
@aduh95 The normal loader commands are |
This landed on node 22: Here is the person who found the "fix" The docs Here is where I first saw the merge |
Affected URL(s)
https://nodejs.org/api/esm.html#esm_no_require_cache
Description of the problem
How do i access the imported packages cache like require.cache?
I am trying to do something like this:
c.mjs
c.js
test.js
This question comes after
https://stackoverflow.com/questions/74215997/how-do-i-do-console-log-in-esm-or-es6-file-without-having-a-package-json-in-the?noredirect=1#comment131031974_74215997
nodejs/help#2806 (comment)
nodejs/help#2806
Note:
I have read this:
I am aware of this docs - https://nodejs.org/api/esm.html#esm_no_require_cache
A simple hack is also fine.
The text was updated successfully, but these errors were encountered: