node-source-map-support icon indicating copy to clipboard operation
node-source-map-support copied to clipboard

Problem with sourceRoot when dealing with nested folder structure

Open akfish opened this issue 11 years ago • 1 comments

Say that I have a project like this:

%project_root%
├─coffee
│  └─sub_folder
│  │    └─bar.coffee
│  └─foo.coffee
├─js
│  └─sub_folder
│  │    └─bar.js
│  └─foo.js
├─map
│  └─sub_folder
│  │    └─bar.js.map
│  └─foo.js.map

If an error was thrown in bar.coffee, the source path would be wrong. There're several cases (tested on Windows, project folder is on drive X:):

sourceRoot Value Source path in error messages for foo.coffee Source path in error messages for sub_folder/bar.coffee
Not set %project_root%/map/foo.coffee %project_root%/map/sub_folder/bar.coffee
/src x:/src/foo.coffee x:/src/sub_folder/bar.coffee
./src %project_root%/map/src/foo.coffee %project_root%/map/src/sub_folder/bar.coffee
../src %project_root%/src/foo.coffee %project_root%/map/src/sub_folder/bar.coffee
__dirname + /src %project_root%/src/foo.coffee` %project_root%/src/sub_folder/bar.coffee

As you can see, only hard-code the absolute path of %project_root% will give us the correct behavior. But it is not very useful since those paths may not be valid on another system.

I think a possible solution would be to resolve sourceRoot path relative to map root instead of each map file's location (introduced by #4), when the sourceRoot is a relative path.

akfish avatar Jul 12 '14 21:07 akfish

I've hit this as well and it does seem like this is a problem. Requiring an absolute path in the sourceRoot is not workable if you want your production environment to report the appropriate file path. Is there no update for this?

TazmanianD avatar Aug 01 '17 19:08 TazmanianD