-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Invalidate imported module cache #5548
Comments
Currently there isn't an API to invalidate the cache, and I am not sure we would want to do that. I think the real use case here is "I dynamically imported a module, but the module changed without restarting the current workload, and I expected that module to reflect that." I think we would have to investigate v8's ability to purge a module that is loaded, because each module exists in the isolate, and so if the module is still referenced, does that change all existing references to that module. Is there a more specific use case of why this would be required? "Hot module reloading" is a bit of a dangerous thing and there are other ways to support development environments. |
I'm developing SSR module like Next.js. It behaves as express's |
the compiler apis may have what you're looking for @keroxp. I'm working on something similar but am running into reload issues that seem to be addressed in #5253. Here's a temporary hacky workaround for single file jsx + no imports const [, bundled] = await Deno.bundle('/entry.js', {
'/entry.js': await readFileStr(pathToJsxEntrypoint),
}) example jsx const Hey = x => (
<div>
<h1>Hey</h1>
{x.children}
</div>
)
const Ho = () => <h1>Ho</h1>
const Root = () => (
<Hey>
<h1>Ayo</h1>
<Ho />
</Hey>
)
ReactDOM.render(<Root />, document.querySelector('#root')) and React + ReactDOM are loaded via script tags at the moment.. yeah not too pretty |
I'm working on a project where a way to invalidate imported module cache would actually be really useful: I'm watching a directory (using The "hack" I found is to first copy the content of the module's file to a temp file, and to import and evaluate the temp file before deleting it. |
For dynamic import you can use the same system as for invalidating cache in a url: await import(`./target.ts?${Math.random()}.ts`); // or with a # instead of ? I keep the extension at the end cause it might be useful when you are using JSX files. The possibility to clear the cache might not be possible with the current implementation of Deno. Deno is using the standard module from V8 and V8 seem to don't support any uncaching feature like this (from my understanding Nodejs is not using the standard module from V8 but instead all import are converted to Another option would be to use web workers to isolate our instance https://deno.land/manual/runtime/workers but right now there is bug in worker, it seem to use the same cache #6116 :-/ Hopefully it will be soon fixed, and we could then handle HMR through workers. |
The expectation of ES Modules is that they instantiated in memory per the specification and cannot be "invalidated" and reloaded. Basically this same restriction applies to Node.js with ESM, though they have a loader API that allows you to hook the resolve and load and there are solutions which handle generating unique modules every time one is requested to support dynamic module replacement. I have opened #8327 to suggest something similar for Deno. Considering what is requested here cannot be achieved given the way ES Modules work, I am closing this in favour of #8327. |
I'm writing code using dynamic module import for dynamically generated code (tool like node-dev). In Deno, once module imported dynamically, they will be never updated while process running. Are there some way to invalidate module cache? In node.js, required module can be deleted.
The text was updated successfully, but these errors were encountered: