I have two files test.js and x.js, in the same directory:
-
test.js:console.log(eval( "require('x.js')" )); -
x.jsis empty.
Expected: require returns undefined, so nothing is logged.
Actual: node test.js gives me Error: Cannot find module 'x.js' (stack-trace omitted for brevity).
The situation sounds similar to this other question, with the differences that I've used eval rather than new Function, and require is defined, just working unexpectedly.
Why is this?
How do I correctly require a module in eval'd code?
Aucun commentaire:
Enregistrer un commentaire