question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next + SWC appear to generate incorrect sourcemaps

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 16.14.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.2.6-canary.2
      eslint-config-next: N/A
      react: 0.0.0-experimental-e7d0053e6-20220325
      react-dom: 0.0.0-experimental-e7d0053e6-20220325

What browser are you using? (if relevant)

N/A

How are you deploying your application? (if relevant)

Vercel, but N/A

Describe the Bug

Next generates different sourcemaps when we switch between using Babel to transpile our code, and SWC. The SWC sourcemaps are incorrect - the mapped output differs from the original source code by a few lines, causing incorrect debugging behavior.

We build https://replay.io , a time-travel debugger for JS. The Replay client uses sourcemaps on both the backend and frontend to parse and display info about the recorded application. In turn, we frequently record replays of our own client app to debug how it’s working.

I’ve made two replays of our codebase built with Next 12.2.6-canary.2 , switching only between using Babel and SWC to transpile:

If you open up debugger/src/actions/event-listeners.ts in both files, you can see that the Babel file correctly maps all of the lines that were hit:

image

In the SWC-built version, the line hit info is off by 3-4 lines.

image

If you open up the sourcemap visualizer tool for both versions, the Babel version is correct:

image

and the SWC version is wrong:

image

Expected Behavior

Using SWC to compile our application would generate sourcemaps that accurately map the original source.

Link to reproduction

https://github.com/replayio/devtools/tree/bugfix/FE-434-next-sourcemaps

To Reproduce

  1. Clone https://github.com/replayio/devtools
  2. Check out commit https://github.com/replayio/devtools/commit/61605c25401897a3486545111e5f9157ef5e3886 , part of the bugfix/FE-434-next-sourcemaps branch.
  3. Run yarn to install
  4. Use Babel to build the app: yarn build, and check the build output + sourcemaps
  5. Check out the tip of the bugfix/FE-434-next-sourcemaps branch, which just disables .babelrc to use SWC for building
  6. Use SWC to build the app: yarnbuild, and check the build output + sourcemaps

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jridgewellcommented, Dec 2, 2022

This should be resolved with https://github.com/swc-project/swc/pull/6561, though that’ll need to be rolled into the next release.

0reactions
markeriksoncommented, Dec 9, 2022

Thank you! We’re still on Next 12 atm, but I’ll try upgrading soon and see what happens.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Features: Next.js Compiler
The Next.js Compiler, written in Rust using SWC, allows Next.js to transform and minify your JavaScript code for production.
Read more >
@swc/core – SWC
SWC is an extensible Rust-based platform for the next generation of fast developer tools. It's used by tools like Next.js, Parcel, and Deno, ......
Read more >
swc_common::SourceMap - Rust - Docs.rs
Given a Span , get a new Span covering the first token without its trailing whitespace or the original Span in case of...
Read more >
Parcel
The zero configuration build tool for the web. ... Parcel's JavaScript compiler, CSS transformer, and source maps implementation are written in Rust for ......
Read more >
TSConfig Reference - Docs on every TSConfig option
jsx.map ) files next to the corresponding .js output file. The .js files will in turn contain a sourcemap comment to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found