question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fresh reload of a module

See original GitHub issue

Can I reload module to get a fresh copy of a particular module? With node, I can delete require.cache and get a new copy. Can I do something similar with browserify?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
M4GNV5commented, Jan 2, 2016

Okay so i know this is not the way its ment to be done and i really think browserify should add some sort of module reloading but looking at browserifys require source i found out every module can actually access the module cache using arguments[5] its a object with a layout something like {numericModuleId: {exports: /* actual module exports */ }, /*.. other modules*/} so i wrote me a little function for removing something from the module cache.

var moduleCache = arguments[5];
function clearFromCache(instance)
{
    for(var key in moduleCache)
    {
        if(moduleCache[key].exports == instance)
        {
            delete moduleCache[key];
            return;
        }
    }
    throw "could not clear instance from module cache";
}

note you parse the module exports to the clear function not the path. basically you can do

//foo.js
var bar = require("./bar.js");
clearFromCache(bar);
var bar = require("./bar.js");

//bar.js
alert("hi");

and it will show 2 alerts.

i cant say often enough that doing it this way is a bad idea and may have some results like infinite loops etc.

0reactions
M4GNV5commented, Dec 5, 2016

glad i could help ^^

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reloading modules in Python - GeeksforGeeks
The reload() is a previously imported module. If you've altered the module source file using an outside editor and want to test the...
Read more >
How do I unload (reload) a Python module? - Stack Overflow
This defines a reload method which can be called with a module to reload it. For example, reload(math) will reload the math module....
Read more >
Reloading a Module - Real Python
In this lesson, you'll learn about reloading a module. For efficiency, a module is only loaded once per interpreter session. That's fine for...
Read more >
Reloading module does not reload submodules. #2505 - GitHub
Import-Module modrepo -Force doesn't reload the nested module of modrepo ( Sub.psm1 in this case) when modrepo was already loaded.
Read more >
Reloading Python modules - PyUnit
A set of modules are loaded; The modules are used; The code is changed; The modules must be used again, but be freshly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found