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

fix(register/esm): pass file urls as paths #840

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

simonbuchan
Copy link
Contributor

compile() expects a filename, not a url: it passes the value directly to the bindings module, which immediately parses it as a Path unconditionally.

This causes input file source maps to fail to load, as it attempts to find the URL as if it were a file on disk. (see swc-project/swc#9422)

This is a targeted fix which hopefully minimizes the chance of things breaking.

compile() expects a filename, not a url: it passes the
value directly to the bindings module, which immediately
parses it as a `Path` unconditionally.

This causes input file source maps to fail to load, as it
attempts to find the URL as if it were a file on disk.
(see swc-project/swc#9422)

This is a targeted fix which hopefully minimizes the chance of things breaking.
@Brooooooklyn Brooooooklyn merged commit 27d922d into swc-project:master Aug 13, 2024
13 checks passed
kdy1 pushed a commit to swc-project/swc that referenced this pull request Aug 14, 2024
**Description:**

Parse based on the provided prefix: inline urls must start with "data:",
so only trying one will ensure the correct and more helpful error
message will be shown.

Currently, any error while trying to load a sourcemap file will give the
unhelpful error:

```
  ERROR  failed to read input source map: failed to parse inline source map url
index.js.map

 Caused by:
     relative URL without a base
     at <snip>/swc-<ver>/src/lib.rs:386
```

Further, for the common "missing file" error, give a better message that
hopefully describes the two paths tried, rather than increasing
confusion by talking about a `.js.map.map` file if it was correct.

Now it will show, for example:

```
  ERROR  failed to read input source map: failed to find input source map file "index.js.map" in "file:///D:/github/skilitics/billing/api-client/lib/services/index.js" file as either "file:///D:/github/skilitics/billing/api-client/lib/services\\index.js.map" or with appended .map
    at D:\github\swc-project\swc\crates\swc\src\lib.rs:400
```

(This example appears to be an issue in swc-node, where it is passing a
file URL which is treated as a path, and therefore never exists, I'm
working on a PR for there too)

There are more improvements that could make this code clearer and more
reliable, but this should resolve many of the confused users (including
me!)

**Related issue:**

See (maybe can be considered to fix): #8944, #8910

[PR in swc-node to fix the originating
issue](swc-project/swc-node#840)
@simonbuchan simonbuchan deleted the fix-transform-filename branch August 29, 2024 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants