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

failed to read input source map - @swc/jest + yarn PnP workspaces #9416

Open
mrginglymus opened this issue Aug 9, 2024 · 12 comments
Open

failed to read input source map - @swc/jest + yarn PnP workspaces #9416

mrginglymus opened this issue Aug 9, 2024 · 12 comments
Labels
Milestone

Comments

@mrginglymus
Copy link

mrginglymus commented Aug 9, 2024

Describe the bug

Using yarn PnP with workspaces causes swc to emit

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

Caused by:
    relative URL without a base

Switching to the node-modules linker, stops the errors.

I'd been seeing this for a while, and hoped that #8789 might fix it, but it appears not to

Input code

// sub-package is a workspace package with a peer dependency
import adder from 'sub-package';

it('tests', () => {
    expect(adder(1, 2)).toEqual(3)
});

Config

export default {
    cache: false,
    transform: {
        "^.+\\.m?(t|j)sx?$": "@swc/jest"
    },
    testPathIgnorePatterns: ["/node_modules/"],
}

Playground link (or link to the minimal reproduction)

https://github.com/mrginglymus/swc-repro

SWC Info output

Operating System:
    Platform: win32
    Arch: x64
    Machine Type: x86_64
    Version: Windows 10 Pro
    CPU: (24 cores)
        Models: Intel(R) Core(TM) i9-10920X CPU @ 3.50GHz

Binaries:
    Node: 22.4.0
    npm: N/A
    Yarn: N/A
    pnpm: N/A

Relevant Packages:
    @swc/core: N/A
    @swc/helpers: N/A
    @swc/types: N/A


SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

No errors :)

Version

1.7.9

Additional context

This only happens when importing code from a workspace package with peer dependencies.

@mrginglymus
Copy link
Author

Sigh. Closing because only after raising this issue I spot the error in my regex. However, hopefully someone else may see this issue and realise their regex is broken too.

@mrginglymus mrginglymus reopened this Aug 9, 2024
@mrginglymus mrginglymus changed the title failed to read input source map - @swc/jest + yarn PnP + transformIgnorePatterns failed to read input source map - @swc/jest + yarn PnP Aug 9, 2024
@mrginglymus mrginglymus changed the title failed to read input source map - @swc/jest + yarn PnP failed to read input source map - @swc/jest + yarn PnP workspaces Aug 9, 2024
@mrginglymus
Copy link
Author

Re-opening as I've finally managed to get a minimal repro of the original issue I was facing relating to importing code from workspace packages with peer dependencies.

@davidmurdoch
Copy link
Contributor

I've been seeing this issue since v1.4.12 :-(

@mrginglymus
Copy link
Author

I see that #9422 suggests it may help with #8910, which is a duplicate of this issue (without a reproduction). I've tried 1.7.11, but I'm still getting the same error message, with no additional details:

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

Caused by:
    relative URL without a base

@mrginglymus
Copy link
Author

It still seems to be using swc-0.283.0 on 1.7.11, which surprised me.

@mrginglymus
Copy link
Author

mrginglymus commented Aug 16, 2024

1.7.12-nightly-20240816.1 has swc-0.284.0 which does give us the improved errors:

ERROR  failed to read input source map: failed to find input source map file "index.js.map" in 
"C:\\Users\\<me>\\git\\<my-project>\\.yarn\\__virtual__\\<my-package>-virtual-c44221b7bd\\1\\packages\\baseline\\dist\\components\\icon\\index.js"
file as either "C:\\Users\\<me>\\git\\<my-project>\\.yarn\\__virtual__\\<my-package>-virtual-c44221b7bd\\1\\packages\\baseline\\dist\\components\\icon\\index.js.map" 
or with appended .map

I can confirm that said file does exist (in packages/baseline/dist/components/icon/index.js.map), so something in swc is failing to resolve Yarn's virtual package folder

@aminya
Copy link

aminya commented Aug 20, 2024

I am facing the same issue but with pnpm's default settings (through Jest)

Here's a reproduction:
https://github.com/aminya/setup-cpp/actions/runs/10480088540/job/29027082748?pr=263#step:8:12

  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 /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.283.0/src/lib.rs:407

@kdy1 kdy1 added this to the Planned milestone Aug 20, 2024
@kdy1
Copy link
Member

kdy1 commented Aug 20, 2024

Can you update @swc/core of your repro? It should be v1.7.14

@kdy1 kdy1 modified the milestones: Planned, Planned (Low priority) Aug 20, 2024
@Zulqarnain-ZQ
Copy link

I have updated @swc/core to v1.7.18 but issue still persists

@ziimakc
Copy link

ziimakc commented Sep 2, 2024

Same issue with pnpm workspaces , source maps are present.

@aminya
Copy link

aminya commented Sep 3, 2024

Now, I have more information in the latest release of swc. For me, the error is actually coming from one of the dependencies that doesn't have the source map in the package.

  ERROR  failed to read input source map: failed to find input source map file "index.js.map" in "/Users/runner/work/setup-cpp/setup-cpp/node_modules/.pnpm/ubuntu-version@2.0.0/node_modules/ubuntu-version/index.js" file as either "/Users/runner/work/setup-cpp/setup-cpp/node_modules/.pnpm/ubuntu-version@2.0.0/node_modules/ubuntu-version/index.js.map" or with appended .map

rhysd/node-ubuntu-version#2

@ruscon
Copy link

ruscon commented Sep 8, 2024

with docker + pnpm workspace and

    "@swc/cli": "0.4.0",
    "@swc/core": "1.7.24",

an error

ERROR  failed to read input source map: failed to read input source map
                               from file at packages/api/src/bootstrap.js.map

Caused by:
   bad json: trailing characters at line 1 column 2816
   at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.286.0/src/lib.rs:400

Plus in my case I can already have compiled js files and swc adds sourceMappingURL comment after each compilation without check if it is already exists.

} //# sourceMappingURL=bootstrap.js.map
 //# sourceMappingURL=bootstrap.js.map
 //# sourceMappingURL=bootstrap.js.map

//# sourceMappingURL=bootstrap.js.map

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

No branches or pull requests

7 participants