-
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
The instanceof operator always returns false when used with the values from imported modules.
const moduleFromString = require("module-from-string");
const code = "throw new Error();";
try {
const x = moduleFromString.requireFromString(code);
} catch (err) {
console.log(Object.getPrototypeOf(err).name === Error.prototype.name);
console.log(err instanceof Error);
console.log(err instanceof Object);
}It outputs:
truefalsefalse
Or:
const moduleFromString = require("module-from-string");
const code = "exports.obj = {}";
const x = moduleFromString.requireFromString(code);
console.log(Object.getPrototypeOf(x.obj).name === Object.prototype.name);
console.log(x.obj instanceof Object);Outputs:
truefalse
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.
Metadata
Metadata
Assignees
Labels
No labels