-
Notifications
You must be signed in to change notification settings - Fork 367
Description
I am currently working building a node endpoint that accepts a minified stack trace from a client, and then uses this library to find the originating line in the un-minified source using a shared copy of the sourcemap.
The problem I'm running into is that the library uses "fetch" feature detection to determine whether the current environment is a browser or node environment.
if (typeof fetch === "function") {
and then conditionally exports a module in the read-wasm file: https://github.com/mozilla/source-map/blob/master/lib/read-wasm.js#L1
The node environment I'm developing within has been configured to use a isomorphic fetch polyfill, so this assumption has caused my node environment to incorrectly use the browser behavior and immediately throw the error:
You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer
I understand that my environment might be a bit different than most, but I'd like to challenge whether making assumptions like this is the correct way of browser vs. node detection. I came across a clever
solution described within this stackoverflow question, https://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser , where you can look up the default top-level function scope of the environment (window vs global). By looking at the default top level scope, this solution will even handle the case where window has been mocked out by a library like jsdom.
I've implemented this in a fork, and it seems to have fixed my problem. Wondering whether this is something you would be open to considering.
Also, if you otherwise think I've done something else completely wrong, please let me know. :)