evanw / node-source-map-support

Adds source map support to node.js (for stack traces)
MIT License
2.16k stars 223 forks source link

are base64 dataurl's supported in sourceMappingURL? #100

Open breathe opened 9 years ago

breathe commented 9 years ago

Does node-source-map-support support inline sourcemaps encoded into data url's?

I'm writing ansible modules in javascript using webpack to package the javascript together into a standalone file. Ansible module's can be written in any language but must be contained in a single file -- hence the usage of webpack to run code on node ... It sounds strange perhaps, but its actually perfect for my usage and works well -- the only annoying thing is I haven't been able to get source-map to work for stack traces ...

Here's a simple example:

Input source:

require("source-map-support").install()

console.log("Hello");

throw Error("give me stack trace!")

And here's a gist showing what the webpack compiled version of the above src looks like ...

https://gist.githubusercontent.com/breathe/debf645ae49e5bd66768/raw/bab77313c1fde689645ff40e3b09fb768a3fb8b9/debug-sourcemap

Running the code in the gist above yields this output ... Any ideas?

Hello
Error: give me stack trace!
    at Error (native)
    at Object.eval (eval at <anonymous> (/Users/ncohen/software/ansible/sts-infrastructure/library/debug-sourcemap:49:2), <anonymous>:7:7)
    at Object.0 (/Users/ncohen/software/ansible/sts-infrastructure/library/debug-sourcemap:49:2)
    at __webpack_require__ (/Users/ncohen/software/ansible/sts-infrastructure/library/debug-sourcemap:21:30)
    at /Users/ncohen/software/ansible/sts-infrastructure/library/debug-sourcemap:41:18
    at Object.<anonymous> (/Users/ncohen/software/ansible/sts-infrastructure/library/debug-sourcemap:44:10)
    at Module._compile (module.js:430:26)
    at Object.Module._extensions..js (module.js:448:10)
    at Module.load (module.js:355:32)
arciisine commented 8 years ago

I'm running into the same issue as above. Is there anything special that needs to be done to support inline maps?

jpommerening commented 8 years ago

I think the issue here is your webpack build. If you have a look at the generated file, you'll see that webpack generates eval calls for each of you modules. That way it probably bypasses source-map-support, which hooks into the NodeJS require mechanism to extract the source maps.

You can configure webpack to generate sourcemaps differently with the devtool option: https://webpack.github.io/docs/configuration.html#devtool

I'm just guessing here, but maybe it'll work if you try devtool: "inline-source-map".