node-hotswap
node-hotswap copied to clipboard
Arrays break it
I tried to enable hotswap for every module (patching it), to see if it works in a real project.
I didn't test the reloading. Just tried to run it.
The app died with undefined is not a function
somewhere deep in the modules (under node_modules
).
I tried to move require('hotswap')
lower in the code, to exclude some modules, so the server actually started running, but then there was another error of the same kind.
To give a glimpse of what's happening:
undefined is not a function
at Object.<anonymous> (/js/javascript-nodejs/node_modules/image-size/lib/detector.js:7:7)
at Module._compile (module.js:460:26)
at extension_js (/js/javascript-nodejs/node_modules/hotswap/hotswap.js:220:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/js/javascript-nodejs/node_modules/image-size/lib/index.js:7:16)
And here I paste the code from the image-size
module (from npm):
'use strict';
var typeMap = {};
var types = require('./types');
// load all available handlers
types.forEach(function (type) {
typeMap[type] = require('./types/' + type).detect;
});
module.exports = function (buffer, filepath) {
var type, result;
for (type in typeMap) {
result = typeMap[type](buffer, filepath);
if (result) {
return type;
}
}
};
Looks like the reason why doesn't work is types
being an array.
I think you could try reload a json file not a js file since the array.