Invalidating the module cache

suggest change

In 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents