Open mtmacdonald opened 1 year ago
Thanks for your suggestion. Actually, requireFromString
has already used the filename
option:
But moduleFilename
from the above code is by default generated as a UUID.
I will expose an option filename
to fix this, it should be just a few lines of code.
As for line offsets, I think it might be possible to reformat the error stack using the sourcemap emitted by esbuild
's transform
function, which importFromString
without --experimental-vm-modules
uses to transform ES Module to CommonJS.
Option filename
is added in v3.3.0
. I will need more time for the line number issue.
Hello, thanks for the great package. I would like to request an improvement to how the package handles stack traces when the imported script throws an exception during execution. In my current usage (
importFromString
without--experimental-vm-modules
enabled, i.e. the one that falls back onrequireFromString
internally), if my imported string throws an exception, the stack trace is unhelpful because:evalmachine.<anonymous>
module-from-string
prepends its own code and also seems to reformat the input stringIs it possible to please improve the stack traces?
One idea/suggestion I have for this is to expose more options from vm.runInNewContext to make this possible, particularly the
filename
andlineOffset
options. I mean roughly like this (then the usages have more control over displaying a meaningful stack trace, although I'm not quite sure how to handle the line offsets given the reformatting of the input - perhaps you could also provide an option to preserve original formatting):What do you think?