Skip to content
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

module: import unload module strategy #5895

Closed
yjhjstz opened this issue Mar 25, 2016 · 13 comments
Closed

module: import unload module strategy #5895

yjhjstz opened this issue Mar 25, 2016 · 13 comments
Labels
feature request Issues that request new features to be added to Node.js. module Issues and PRs related to the module subsystem.

Comments

@yjhjstz
Copy link

yjhjstz commented Mar 25, 2016

A module always loaded in cache. If we only use once, I recommend add strategy to unload the module.
Like the linux kernel do.

@mscdex mscdex added module Issues and PRs related to the module subsystem. feature request Issues that request new features to be added to Node.js. labels Mar 25, 2016
@bnoordhuis
Copy link
Member

To what purpose?

@yjhjstz
Copy link
Author

yjhjstz commented Mar 26, 2016

To reduce memory use. @bnoordhuis

@bnoordhuis
Copy link
Member

I don't think that would make a significant difference. V8 is going to keep the script source in memory anyway.

@yjhjstz
Copy link
Author

yjhjstz commented Mar 26, 2016

Maybe V8 can provide API to remove script source. And unload a module and reload is useful for hot patch.

@bnoordhuis
Copy link
Member

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
Copy link

SEAPUNK commented Mar 26, 2016

I've always been under the impression that require.cache was an undocumented part of require, but I just now found it, my bad.

@coreyleelarson
Copy link

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.

@SEAPUNK
Copy link

SEAPUNK commented Mar 26, 2016

@coreyleelarson If you transpile your modules with Babel, babel converts import into require(), because node currently doesn't support ES6 modules just yet.

@coreyleelarson
Copy link

@SEAPUNK It must be something else I'm doing wrong, then.

@jasnell
Copy link
Member

jasnell commented May 17, 2016

-1 on this, given that the discussion seems to have dropped off, closing. Can reopen if necessary.

@jasnell jasnell closed this as completed May 17, 2016
@naturalethic
Copy link

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.

@devsnek
Copy link
Member

devsnek commented 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
Copy link

I need this to test a file that has an IIFE on the top level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. module Issues and PRs related to the module subsystem.
Projects
None yet
Development

No branches or pull requests

9 participants