You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the line 73 is called _compile() and it results into empty object when the content of required module is JSON. I changed my code and assign result of JSON.parse() directly to exports, if extension is '.json'. I'm not sure if it is correct fix and maybe it brings other issues.
The text was updated successfully, but these errors were encountered:
I hook to both
hook.hook('.js', logLoadedFilename);
hook.hook('.json', logLoadedFilename);
and even if I do nothing with the source, e.g.
function logLoadedFilename(source, filename) {
return source;
}
running of the script fails. I've digged into and realised, that one require of json file returns empty object. I stepped into your hook function and . . .
#72 if (typeof ret === 'string') { // JSON string is in ret, so everything is ok
#73 module._compile(ret, filename); // empty obj is in ret
#74 } else ...
I hot fixed it like this
if (typeof ret === 'string') {
if (extension=='.js') {
module._compile(ret, filename);
} else {
module.exports=JSON.parse(source);
}
} else ...
Module hooking is amazing fun, and thank you for introduction in it. Now I'm experimenting with lower level of it, with fs.readFileSync hooking :-)
On the line 73 is called _compile() and it results into empty object when the content of required module is JSON. I changed my code and assign result of JSON.parse() directly to exports, if extension is '.json'. I'm not sure if it is correct fix and maybe it brings other issues.
The text was updated successfully, but these errors were encountered: