You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
V8 uses the script source whenever it optimizes or deoptimizes a function. It's also needed for Function.prototype.toString() and, because a module in node.js is basically one big function, that means it retains the script source in its entirety.
However, if you want to reload modules, you can do that by manipulating require.cache.
Does import cache modules any differently than require? I always thought it was just syntactic sugar over require. I'm attempting to reload modules on file change and clearing the require.cache only seems to work when I use require on the module.
Let's re-open. This issue is quite old, however with ES6 modules now, one may desire to invalidate a module that has changed during development. I haven't found any documentation of this feature, only this ticket.
Reacted by Corey Larson, Ovidiu Dolha, xiao, Felicio, Michael Fiford and Simon Siefke
Activity
bnoordhuis commentedon Mar 25, 2016
To what purpose?
yjhjstz commentedon Mar 26, 2016
To reduce memory use. @bnoordhuis
bnoordhuis commentedon Mar 26, 2016
I don't think that would make a significant difference. V8 is going to keep the script source in memory anyway.
yjhjstz commentedon Mar 26, 2016
Maybe V8 can provide API to remove script source. And unload a module and reload is useful for hot patch.
bnoordhuis commentedon Mar 26, 2016
V8 uses the script source whenever it optimizes or deoptimizes a function. It's also needed for
Function.prototype.toString()and, because a module in node.js is basically one big function, that means it retains the script source in its entirety.However, if you want to reload modules, you can do that by manipulating
require.cache.SEAPUNK commentedon Mar 26, 2016
I've always been under the impression that
require.cachewas an undocumented part ofrequire, but I just now found it, my bad.coreyleelarson commentedon Mar 26, 2016
Does
importcache modules any differently thanrequire? I always thought it was just syntactic sugar overrequire. I'm attempting to reload modules on file change and clearing therequire.cacheonly seems to work when I userequireon the module.SEAPUNK commentedon Mar 26, 2016
@coreyleelarson If you transpile your modules with Babel, babel converts
importintorequire(), because node currently doesn't support ES6 modules just yet.coreyleelarson commentedon Mar 26, 2016
@SEAPUNK It must be something else I'm doing wrong, then.
jasnell commentedon May 17, 2016
-1 on this, given that the discussion seems to have dropped off, closing. Can reopen if necessary.
naturalethic commentedon May 31, 2018
Let's re-open. This issue is quite old, however with ES6 modules now, one may desire to
invalidatea module that has changed during development. I haven't found any documentation of this feature, only this ticket.devsnek commentedon May 31, 2018
@naturalethic you can go check if an issue on https://github.com/nodejs/modules doesn't already include this and then open one there.
alshdavid commentedon Jun 9, 2020
I need this to test a file that has an IIFE on the top level