Script is not only loaded when you save changes : it is reloaded randomly, then your scope is reset. You can do a "console.log" outside the returned module to see when it happens. I wonder if something like this could be benefical :main.js console.log("scope resetted")const core = new require("core")();exports.loop = function(){ return core.loop()}