node-source-map-support icon indicating copy to clipboard operation
node-source-map-support copied to clipboard

Use sourcemap inside of code executed by eval()

Open holtwick opened this issue 5 years ago • 1 comments

Currently, I use esbuild to compile code and dynamically transpile and execute user JS using eval(), like this:

try {
    if (code) {
      code = `(function(exports) {
        ${code}
        return exports;
      })({})`
      mod = eval(code)
    }
  } catch (err) {
    console.error('Exception:', err)
  }

The code contains a sourcemap.

Is there a way to use node-source-map-support to print the exception's stack using the sourcemap info?

holtwick avatar Oct 23 '20 14:10 holtwick

@holtwick I just ran into this myself. I’m not sure this is a supported use-case. Anyway, I found this article you wrote: https://dev.to/holtwick/esbuild-is-fast-2cjj which helped me a lot personally. For now I’m writing a hidden file to disk in the same root directory so that requires can resolve as expected and then unlinking the same you do when processing is done.

If you want to exchange notes, feel free to HMU https://twitter.com/username_ZAYDEK.

zaydek avatar Mar 08 '21 13:03 zaydek