evanw / evanw/node-source-map-support

if require('coffee-script').register() is called after require('source-map-support').install() then source maps no longer function for exception traces

Open
#34 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.2k
Forks
223
PR merge metrics
No merged PRs in 30d

Description

Here is the demo modified to demonstrate the issue:

``` coffee
require('source-map-support').install()
require("coffee-script").register()

foo = ->
bar = -> throw new Error 'this is a demo'
bar()
foo()
```

I encounter this problem because I have a module which is intended to 'require' some 'user' editable coffee-script configuration code -- if at any time after initializing source-map-support I later initialize the coffee-script support so that the node module loader can require .coffee files without pre-compiling, then the source-map-support exception rewriting behavior fails to function globally in my app ...

If I change the order the source-map-support and coffee-script modules are initialized in, then things work as expected:

``` coffee
require("coffee-script").register()
require('source-map-support').install()

foo = ->
bar = -> throw new Error 'this is a demo'
bar()
foo()
```

However this means I need to _ensure_ that my process initializes the coffee-script module prior to initializing the source-map-support module -- even if enter my code through paths for which coffee-script support is not required at that time ... Particularly I encountered this issue when unit testing -- units tests give arbitrary entry points into my application's code where I wouldn't have thought I would need to initialize the coffee-script module unless/until its needed ... its a bit ugly that I _must_ initialize coffee-script within the context of my unit tests so that I can enforce correct initialization order of the two modules ...

Is there a good workaround for this? The safest thing I can come up with is to add a new module which initializes both source-map-support and coffee-script in the correct order in my code -- and use that throughout my project's code anywhere I would've used require('source-map-support').install() ...

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.