Skip to content

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

@breathe

Description

@breathe

Here is the demo modified to demonstrate the issue:

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:

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() ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions