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
The instanceof operator always returns false when used with the values from imported modules.
constmoduleFromString=require("module-from-string");constcode="throw new Error();";try{constx=moduleFromString.requireFromString(code);}catch(err){console.log(Object.getPrototypeOf(err).name===Error.prototype.name);console.log(errinstanceofError);console.log(errinstanceofObject);}
Using importFromString yields the same results. It's a side effect of using runInNewContext instead of runInThisContext (or providing context in case of the vm.Module). If this behavior is not intentional, I would be glad to fix it.
The text was updated successfully, but these errors were encountered:
This is intentional, but I have added an option useCurrentGlobal and some factory functions createRequireFromString etc. in the pre-released version 3.2.0-0. You can install it and give it a try.
If it works well, I will update the README and publish a new minor version tomorrow.
Thank you. Just a question about the implementation though, did you consider the compileFunction approach that the default nodejs cjs loader takes (here)? That way, there would be no need to shallow copy the entire global object each time.
The
instanceof
operator always returnsfalse
when used with the values from imported modules.It outputs:
true
false
false
Or:
Outputs:
true
false
Using
importFromString
yields the same results. It's a side effect of usingrunInNewContext
instead ofrunInThisContext
(or providing context in case of thevm.Module
). If this behavior is not intentional, I would be glad to fix it.The text was updated successfully, but these errors were encountered: