vercel / vercel/next.js

Inaccurate sourcemaps for sources under node_modules

Open
#53,253 15 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Verify canary release
  • I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #85~20.04.1-Ubuntu SMP Mon Jul 17 09:42:39 UTC 2023
Binaries:
  Node: 18.16.0
  npm: 9.5.1
  Yarn: 1.22.18
  pnpm: 8.6.7
Relevant Packages:
  next: 13.4.12
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

https://github.com/replayio/nextjs-inaccurate-sourcemaps

To Reproduce

Alternatively, you can look at these sourcemaps here:

Describe the Bug

I've noticed that the sourcemaps produced by Next.js are inaccurate for some sources, making it impossible for debuggers to show scopes with original (rather than generated) variable names.
This seems to be the case for all sources under node_modules.
To reproduce the problem I've used create-next-app to create an app and copied node_modules/@swc/helpers/esm/_interop_require_wildcard.js to src/_interop_require_wildcard.js. This is what a sourcemap visualizer shows for these two copies of the same source:

node_modules/@swc/helpers/esm/_interop_require_wildcard.js:

Screenshot_2023-07-27_13-49-26

src/_interop_require_wildcard.js:

Screenshot_2023-07-27_13-50-09

Expected Behavior

Sourcemaps for sources under node_modules should be accurate.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository and run npm run build. Compare the sourcemaps for .next/static/chunks/main-26f0defd1fe4aedb.js and pages/_app-27374a655d3a2ebe.js, focusing on the node_modules/@swc/helpers/esm/_interop_require_wildcard.js and src/_interop_require_wildcard.js sources. Done means sources under node_modules produce accurate mappings like the copied source.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
build-system, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.