Invalidating the module cache
suggest changeIn development, you may find that using require() on the same module multiple times always returns the same module, even if you have made changes to that file. This is because modules are cached the first time they are loaded, and any subsequent module loads will load from the cache.
To get around this issue, you will have to delete the entry in the cache. For example, if you loaded a module:
var a = require('./a');
You could then delete the cache entry:
var rpath = require.resolve('./a.js');
delete require.cache[rpath];
And then require the module again:
var a = require('./a');
This is a development trick. delete removes the cache entry only. Any module that already called require keeps the old exports object, so the rest of the graph is not reloaded. Restart the process in production.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents