Skip to content
Sign upLog in
← Back to Community
require.cache undefined, require.resolve() invalid function
Profile icon
kbaumgart

I'm creating a bot to post to Discord, and looking for a way to reload required modules without having to stop/start the bot. Based on my reading, I should be able to delete the key from require.cache after resolving the location of the module. however on repl.it require.resolve() always returns as an invalid function and require.cache is always undefined. are these methods disabled? does anyone have another idea as to how to go about reloading the module after file changes?

Voters
Profile icon
k471352
Profile icon
atav32
Profile icon
CheesyZaem
Profile icon
phuz
Profile icon
kbaumgart
Comments
hotnewtop
Profile icon
atav32

How about

content = fs.readFileSync(path, 'utf8'); module._compile(content, path);

You might also be able to use module.load(path), https://github.com/nodejs/node/blob/master/lib/internal/modules/cjs/loader.js#L961

Profile icon
atav32
Profile icon
atav32

@kbaumgart
did you figure anything out since posting the question? Just ran into this myself

Profile icon
RichiOV

I couldn't make it work, do you know what can be [email protected]