Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapRoot/sourceRoot write sourcemaps using absolute local paths, not URIs #25587

Closed
roblourens opened this issue Jul 11, 2018 · 5 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@roblourens
Copy link
Member

roblourens commented Jul 11, 2018

From microsoft/vscode#54026

//tsconfig.json

{
    "compilerOptions": {
        "sourceMap": true,
        "sourceRoot": "src/",
        "mapRoot": "build/"
    }
}

./src/hello.ts exists

Actual

I run tsc and get:

hello.js:

console.log("hello world!");
//# sourceMappingURL=/Users/roblou/Downloads/tsTest/build/hello.js.map

hello.map.js:

{"version":3,"file":"hello.js","sourceRoot":"/Users/roblou/Downloads/tsTest/src/","sources":["hello.ts"], ...

Expected

This stuff is not clearly spec'd but my understanding is that sourceMappingURL and sourceRoot should be URIs or relative paths, not local absolute paths. In a browser, a path starting with / should be interpreted as relative to the webserver root.

In Node, Chrome Devtools handles this on Mac, but on Windows, it can't handle a sourceMappingUrl or sourceRoot as a windows-style absolute path. That is what convinces me that this is worth fixing on TS's end.

In vscode, I plan to try to support this scenario somehow, since it previously worked.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 11, 2018

Looks like a duplicate of #23180. should be fixed by #23989. can you give typescript@next a test and let us know if you are still running into issues.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jul 11, 2018
@roblourens
Copy link
Member Author

roblourens commented Jul 11, 2018

The paths are indeed now not absolute paths, but I'm not sure whether they are right. I'm not sure what's expected. Let me know if you'd prefer that I fork this to a new issue.

Using the same example from above, I get

//# sourceMappingURL=build/hello.js.map

and

"sourceRoot":"src/"

But since these are relative paths, I think I expect //# sourceMappingURL=../build/hello.js.map and "sourceRoot": "../src/".

@mhegazy
Copy link
Contributor

mhegazy commented Jul 11, 2018

the sourceRoot / mapRoot are used verbatim. so you can have in there whatever you want, the compiler does not really change these. so you can use / to refer to your site root for instance.

@roblourens
Copy link
Member Author

I see, I basically get the behavior I expect without those options or just with outDir, and these are for someone who wants to override that in some specific situation.

@cordiosd
Copy link

We set up our build process leveraging the absolute paths provided by this feature. Since we build our libraries (individual packages) and then move them to other node_modules folders, the absolute paths worked great. That is until we needed to develop/debug on OSX. The source-map-loader webpack loader does not appear to be able to differentiate between an absolute and relative path on a unix style OS like OSX. While investigating this, we found that if you set the sourceRoot from the command line, it works completely differently than if you set it in the tsconfig.json file. We are still on tsc version 2.6.2. The only way to get the absolute path when setting sourceRoot from the command is to pass it in as "$pwd/src". There appears to be no way to not have the sourceRoot produce a non absolute path if you set sourceRoot in the tsconfig.json file.

Through experimentation, we have found a work around to this. But it is a bit quirky. We need to write a post processor for each map file so after it is copied to its target location, the sourceRoot or sources are modified so they work in their new location. In an ideal world:

  1. tsc would work consistently between the settings in the tsconfig.json and the cli options and we could indicate we wanted absolute paths or relative for the two different use cases different developers use.
  2. source-map-loader would not have an issue with these absolute paths on linux

If you already addressed these items, thank you. If not, hopefully this additional scenario will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants