Last active
January 4, 2022 01:47
-
-
Save adam-lynch/11037907 to your computer and use it in GitHub Desktop.
Require a module, without going to Node.js's require cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var _invalidateRequireCacheForFile = function(filePath){ | |
delete require.cache[path.resolve(filePath)]; | |
}; | |
var requireNoCache = function(filePath){ | |
_invalidateRequireCacheForFile(filePath); | |
return require(filePath); | |
}; |
Suppose there's no way to avoid caching as it seems. require
ing and then invalidating is a two step process...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work for me but thanks anyway!
Should use
require.resolve
as @facekapow metioned.