evanw / node-source-map-support

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

Activating source-map-support several times leads to issues #200

Open renehamburger opened 6 years ago

renehamburger commented 6 years ago

I've just encountered the fact that Protractor tests in TypeScript run via ts-node leads to broken stack traces, as both Protractor and ts-node call require('source-map-support').install() by default. See this issue at ts-node and this example repo.

In this case, the solution is simple, as Protactor allows to switch off source map support, but it would be worth to either investigate this bug or log an error message to notify the user that souce-map-support was activated twice.

LinusU commented 6 years ago

Maybe it would be good to guard against double initialisation with a simple global variable? Would you be up for making a pr?

kasperisager commented 6 years ago

I'm having the same issue when using ts-node in combination with node-tap; lines and columns in stack traces are way off.

novemberborn commented 6 years ago

One problem is different packages loading different versions of source-map-support. Going forward, I think if a registered Symbol could be added to prepareStackTrack, that could be used to avoid overwriting a previous installation.

That said we may also need a way to register multiple retrievers, even across source-map-support packages.

This has been affecting AVA, see https://github.com/avajs/ava/issues/1899#issuecomment-416204989 for my latest investigation into the matter.

ghost commented 4 years ago

Still running into this problem two years later. As @LinusU mentioned, a simple global variable should suffice for this. Is there a reason why a fix hasn't been included yet, i.e. is it not that simple?

krzkaczor commented 3 years ago

@evanw @LinusU I am more than happy to make a PR to fix this. Should I go ahead?

This is still causing some problems. Related issues: https://github.com/nomiclabs/hardhat/issues/1336 and https://github.com/EthWorks/Waffle/issues/281

krzkaczor commented 3 years ago

This library already detects if a particular version is loaded multiple times. If you use yarn you can force it to always install only one version.

In package.json:

"resolutions": {
    "source-map-support": "0.5.19"
  }

This is a quite reasonable workaround IMO.