Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sourcemap inside of code executed by eval() #284

Open
holtwick opened this issue Oct 23, 2020 · 1 comment
Open

Use sourcemap inside of code executed by eval() #284

holtwick opened this issue Oct 23, 2020 · 1 comment

Comments

@holtwick
Copy link

holtwick commented Oct 23, 2020

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?

@zaydek
Copy link

zaydek commented Mar 8, 2021

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants