Skip to content

Turbopack: fix incorrect esm binding spans #81407

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

Open
wants to merge 8 commits into
base: canary
Choose a base branch
from

Conversation

mischnic
Copy link
Contributor

@mischnic mischnic commented Jul 8, 2025

Fixes incorrect sourcemaps discovered by @eps1lon in #81375

There is no point in including the span at every single level of the mapping here, it just makes it worse.

Before:

Bildschirmaufnahme 2025-07-08 um 13.10.03.mov (uploaded via Graphite)

After:

Bildschirmaufnahme 2025-07-08 um 13.15.25.mov (uploaded via Graphite)

@ijjk ijjk added created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js. labels Jul 8, 2025
Copy link
Contributor Author

mischnic commented Jul 8, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@mischnic mischnic marked this pull request as ready for review July 8, 2025 11:20
@mischnic mischnic requested a review from a team July 8, 2025 11:22
@ijjk
Copy link
Member

ijjk commented Jul 8, 2025

Failing test suites

Commit: 548e037

pnpm test-dev-turbo test/development/acceptance-app/rsc-runtime-errors.test.ts (turbopack)

  • Error overlay - RSC runtime errors > should show runtime errors if invalid server API from node_modules is executed
Expand output

● Error overlay - RSC runtime errors › should show runtime errors if invalid server API from node_modules is executed

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `Error overlay - RSC runtime errors should show runtime errors if invalid server API from node_modules is executed 1`

- Snapshot  - 3
+ Received  + 3

  {
    "description": "`cookies` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context",
    "environmentLabel": null,
    "label": "Runtime Error",
-   "source": "app/client/page.js (4:15) @ Page
+   "source": "app/client/page.js (4:16) @ Page
  > 4 |   callServerApi()
-     |               ^",
+     |                ^",
    "stack": [
-     "Page app/client/page.js (4:15)",
+     "Page app/client/page.js (4:16)",
    ],
  }

  54 |     // TODO(veil): Inconsistent cursor position
  55 |     if (isTurbopack) {
> 56 |       await expect(browser).toDisplayRedbox(`
     |                             ^
  57 |        {
  58 |          "description": "\`cookies\` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context",
  59 |          "environmentLabel": null,

  at Object.toDisplayRedbox (development/acceptance-app/rsc-runtime-errors.test.ts:56:29)

Read more about building and testing Next.js in contributing.md.

pnpm test-dev-turbo test/development/app-dir/error-overlay/error-ignored-frames/error-ignored-frames.test.ts (turbopack)

  • error-ignored-frames > should be able to collapse ignored frames in interleaved call stack
Expand output

● error-ignored-frames › should be able to collapse ignored frames in interleaved call stack

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `error-ignored-frames should be able to collapse ignored frames in interleaved call stack 1`

- Snapshot  - 1
+ Received  + 1

  at <unknown> (app/interleaved/page.tsx (7:11))
- at Page (app/interleaved/page.tsx (6:35))
+ at Page (app/interleaved/page.tsx (6:36))

  53 |     const defaultStack = await getStackFramesContent(browser)
  54 |     if (isTurbopack) {
> 55 |       expect(defaultStack).toMatchInlineSnapshot(`
     |                            ^
  56 |        "at <unknown> (app/interleaved/page.tsx (7:11))
  57 |        at Page (app/interleaved/page.tsx (6:35))"
  58 |       `)

  at Object.toMatchInlineSnapshot (development/app-dir/error-overlay/error-ignored-frames/error-ignored-frames.test.ts:55:28)

Read more about building and testing Next.js in contributing.md.

pnpm test test/integration/edge-runtime-dynamic-code/test/index.test.js (turbopack)

  • Edge route usage of dynamic code evaluation > development mode > shows a warning when running code with eval
  • Middleware usage of dynamic code evaluation > development mode > shows a warning when running code with eval
Expand output

● Middleware usage of dynamic code evaluation › development mode › shows a warning when running code with eval

expect(received).toContain(expected) // indexOf

Expected substring: "

  at usingEval (../../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:11:16)
  at middleware (../../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/middleware.js:12:52)
     9 | export async function usingEval() {"
  Received string:    " ⚠ Webpack is configured while Turbopack is not, which may cause problems.
   ⚠ See instructions if you need to configure Turbopack:
    https://nextjs.org/docs/app/api-reference/next-config-js/turbopack·
   ⚠ DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime
  Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
  at usingEval (../../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:11:16)
  at middleware (../../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/middleware.js:12:53)
     9 | export async function usingEval() {
    10 |   // eslint-disable-next-line no-eval
  > 11 |   return { value: eval('100') }
       |                ^
    12 | }
    13 |
    14 | export async function notUsingEval() {
  "
  at Object.toContain (integration/edge-runtime-dynamic-code/test/index.test.js:109:28)

● Edge route usage of dynamic code evaluation › development mode › shows a warning when running code with eval

expect(received).toContain(expected) // indexOf

Expected substring: "

  at usingEval (../../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:11:16)
  at handler (../../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:13:22)
      at"
  Received string:    " ⚠ Webpack is configured while Turbopack is not, which may cause problems.
   ⚠ See instructions if you need to configure Turbopack:
    https://nextjs.org/docs/app/api-reference/next-config-js/turbopack·
   ✓ Compiled /api/route in 253ms
   ⚠ DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime
  Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
  at usingEval (../../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:11:16)
  at handler (../../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:13:23)
  at NoopContextManager.with (../../../test/integration/edge-runtime-dynamic-code/packages/next/dist/compiled/@opentelemetry/api/index.js:1:7061)
  at ContextAPI.with (../../../test/integration/edge-runtime-dynamic-code/packages/next/dist/compiled/@opentelemetry/api/index.js:1:518)
  at NoopTracer.startActiveSpan (../../../test/integration/edge-runtime-dynamic-code/packages/next/dist/compiled/@opentelemetry/api/index.js:1:18093)
  at ProxyTracer.startActiveSpan (../../../test/integration/edge-runtime-dynamic-code/packages/next/dist/compiled/@opentelemetry/api/index.js:1:18853)
  at NoopContextManager.with (../../../test/integration/edge-runtime-dynamic-code/packages/next/dist/compiled/@opentelemetry/api/index.js:1:7061)
  at ContextAPI.with (../../../test/integration/edge-runtime-dynamic-code/packages/next/dist/compiled/@opentelemetry/api/index.js:1:518)
  at NoopContextManager.with (../../../test/integration/edge-runtime-dynamic-code/packages/next/dist/compiled/@opentelemetry/api/index.js:1:7061)
  at ContextAPI.with (../../../test/integration/edge-runtime-dynamic-code/packages/next/dist/compiled/@opentelemetry/api/index.js:1:518)
     9 | export async function usingEval() {
    10 |   // eslint-disable-next-line no-eval
  > 11 |   return { value: eval('100') }
       |                ^
    12 | }
    13 |
    14 | export async function notUsingEval() {
   GET /api/route?case=using-eval 200 in 91ms
  "
  at Object.toContain (integration/edge-runtime-dynamic-code/test/index.test.js:123:28)

Read more about building and testing Next.js in contributing.md.

pnpm test-dev test/development/app-dir/server-navigation-error/server-navigation-error.test.ts

  • server-navigation-error > middleware > should error on navigation API redirect
Expand output

● server-navigation-error › middleware › should error on navigation API redirect

page.reload: net::ERR_ABORTED; maybe frame was detached?
Call log:
  - waiting for navigation until "load"

  331 |     // do not preserve the previous chained value, it's likely to be invalid after a reload.
  332 |     return this.startChain(async () => {
> 333 |       await page.reload()
      |                  ^
  334 |     })
  335 |   }
  336 |   setDimensions({ width, height }: { height: number; width: number }) {

  at reload (lib/browsers/playwright.ts:333:18)
  at Playwright._chain (lib/browsers/playwright.ts:568:23)
  at Playwright._chain [as startChain] (lib/browsers/playwright.ts:549:17)
  at Playwright.startChain [as refresh] (lib/browsers/playwright.ts:332:17)
  at Object.refresh (development/app-dir/server-navigation-error/server-navigation-error.test.ts:82:21)

Read more about building and testing Next.js in contributing.md.

pnpm test-start-turbo test/e2e/app-dir/segment-cache/cdn-cache-busting/cdn-cache-busting.test.ts (turbopack)

  • segment cache (CDN cache busting) > perform fully prefetched navigation when a third-party proxy performs a redirect
Expand output

● segment cache (CDN cache busting) › perform fully prefetched navigation when a third-party proxy performs a redirect

Expected a response containing the given string:

Target page

  113 |       })
  114 |
> 115 |       await act(
      |             ^
  116 |         async () => {
  117 |           const linkToggle = await browser.elementByCss(
  118 |             '[data-link-accordion="/redirect-to-target-page"]'

  at Object.act (e2e/app-dir/segment-cache/cdn-cache-busting/cdn-cache-busting.test.ts:115:13)

Read more about building and testing Next.js in contributing.md.

pnpm test-dev-turbo test/e2e/app-dir/server-source-maps/server-source-maps.test.ts (turbopack)

  • app-dir - server source maps > stack frames are ignore-listed in ssr
Expand output

● app-dir - server source maps › stack frames are ignore-listed in ssr

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `app-dir - server source maps stack frames are ignore-listed in ssr 1`

- Snapshot  - 5
+ Received  + 5

@@ -7,15 +7,15 @@
       |                 ^",
    "stack": [
      "logError app/ssr-error-log-ignore-listed/page.js (9:17)",
      "runWithInternalIgnored app/ssr-error-log-ignore-listed/page.js (19:13)",
      "<FIXME-file-protocol>",
-     "runWithExternalSourceMapped app/ssr-error-log-ignore-listed/page.js (18:28)",
+     "runWithExternalSourceMapped app/ssr-error-log-ignore-listed/page.js (18:29)",
      "<FIXME-file-protocol>",
-     "runWithExternal app/ssr-error-log-ignore-listed/page.js (17:31)",
-     "runWithInternalSourceMapped app/ssr-error-log-ignore-listed/page.js (16:17)",
+     "runWithExternal app/ssr-error-log-ignore-listed/page.js (17:32)",
+     "runWithInternalSourceMapped app/ssr-error-log-ignore-listed/page.js (16:18)",
      "<FIXME-file-protocol>",
-     "runWithInternal app/ssr-error-log-ignore-listed/page.js (15:27)",
+     "runWithInternal app/ssr-error-log-ignore-listed/page.js (15:28)",
      "runInternal internal-pkg/index.js (2:10)",
-     "Page app/ssr-error-log-ignore-listed/page.js (14:13)",
+     "Page app/ssr-error-log-ignore-listed/page.js (14:14)",
    ],
  }

  174 |         // TODO(veil): Turbopack errors because it thinks the sources are not part of the project.
  175 |         // TODO(veil-NDX-910): Turbopack's sourcemap loader drops `ignoreList` in browser sourcemaps.
> 176 |         await expect(browser).toDisplayCollapsedRedbox(`
      |                               ^
  177 |          {
  178 |            "description": "ssr-error-log-ignore-listed",
  179 |            "environmentLabel": null,

  at Object.toDisplayCollapsedRedbox (e2e/app-dir/server-source-maps/server-source-maps.test.ts:176:31)

Read more about building and testing Next.js in contributing.md.

pnpm test-start test/e2e/app-dir/segment-cache/revalidation/segment-cache-revalidation.test.ts

  • segment cache (revalidation) > refetch visible Form components after cache is revalidated
Expand output

● segment cache (revalidation) › refetch visible Form components after cache is revalidated

thrown: "Exceeded timeout of 120000 ms for a test.
Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

   97 |   })
   98 |
>  99 |   it('refetch visible Form components after cache is revalidated', async () => {
      |   ^
  100 |     // This is the same as the previous test, but for forms. Since the
  101 |     // prefetching implementation is shared between Link and Form, we don't
  102 |     // bother to test every feature using both Link and Form; this test should

  at it (e2e/app-dir/segment-cache/revalidation/segment-cache-revalidation.test.ts:99:3)
  at Object.describe (e2e/app-dir/segment-cache/revalidation/segment-cache-revalidation.test.ts:7:1)

Read more about building and testing Next.js in contributing.md.

Copy link

codspeed-hq bot commented Jul 8, 2025

CodSpeed Performance Report

Merging #81407 will not alter performance

Comparing mischnic/fix-esm-binding-span (5419c6e) with canary (9170aca)

Summary

✅ 9 untouched benchmarks

@ijjk ijjk added the tests label Jul 8, 2025
@mischnic mischnic requested a review from eps1lon July 8, 2025 12:09
@mischnic mischnic force-pushed the mischnic/fix-esm-binding-span branch from 0d20352 to 5419c6e Compare July 8, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
created-by: Turbopack team PRs by the Turbopack team. tests Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants