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

Source maps containing https:// urls get mangled #3613

Closed
lucacasonato opened this issue Jan 26, 2024 · 1 comment
Closed

Source maps containing https:// urls get mangled #3613

lucacasonato opened this issue Jan 26, 2024 · 1 comment

Comments

@lucacasonato
Copy link
Contributor

When an input file has a sourcemap with a http: URL in the "sources" section, esbuild mangles it.

index.js

import "./foo/index.js";

foo/index.js

// index.js
throw new Error();
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiaHR0cHM6Ly9leGFtcGxlLmNvbS9pbmRleC5qcyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsidGhyb3cgbmV3IEVycm9yKCk7Il0sCiAgIm1hcHBpbmdzIjogIjtBQUFBLE1BQU0sSUFBSTsiLAogICJuYW1lcyI6IFtdCn0K

The source map of the above file looks like this:

{
  "version": 3,
  "sources": ["https://example.com/index.js"],
  "sourcesContent": ["throw new Error();"],
  "mappings": ";AAAA,MAAM,IAAI;",
  "names": []
}

Then run:

esbuild --bundle --format=esm --sourcemap=inline index.js > index.dist.js

This generates the following file:

// foo/index.js
throw new Error();
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiZm9vL2h0dHBzOi9leGFtcGxlLmNvbS9pbmRleC5qcyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsidGhyb3cgbmV3IEVycm9yKCk7Il0sCiAgIm1hcHBpbmdzIjogIjtBQUFBLE1BQU0sSUFBSSxNQUFBOyIsCiAgIm5hbWVzIjogW10KfQo=

This contains the following source map:

{
  "version": 3,
  "sources": ["foo/https:/example.com/index.js"],
  "sourcesContent": ["throw new Error();"],
  "mappings": ";AAAA,MAAM,IAAI,MAAA;",
  "names": []
}

You can see that the sources URL here is foo/https:/example.com/index.js even though it should be https://example.com/index.js.

Possibly related #1745

@evanw
Copy link
Owner

evanw commented Feb 6, 2025

Closing as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants