Unverified Commit 2a3bf9ae authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

fix(turbopack): trace cyclic modules to explicit entries (#98661)

### What?

Makes Turbopack import tracing recognize the module graph's explicit
entries as roots, including when an entry participates in an import
cycle. Adds focused graph-level coverage and a Next.js production
fixture that exercises issue formatting through a cyclic graph.

If a malformed graph still has no path to any explicit entry, tracing
now returns a minimal trace and emits a bug-severity issue instead of
panicking.

### Why?

The import tracer inferred roots from nodes with no incoming edges. A
valid cycle that points back to an entry gives every node an incoming
edge, so the tracer could not find a root and panicked while formatting
another diagnostic. The graph already records its entries explicitly,
making them the authoritative and cycle-safe definition of a root.

The same topology-based assumption affected entry membership checks, so
those now use the explicit entry list as well.

### How?

- Resolve import-trace paths against node indices derived from
`GraphEntries`.
- Preserve a defensive fallback for malformed graphs and classify that
invariant violation as an implementation bug.
- Cover cyclic entry paths, malformed rootless graphs, absent paths, and
the product-level issue-formatting path.

Fixes #98205

<!-- NEXT_JS_LLM -->


<!-- fleet 25b26044-3397-4642-a77f-c565b7577046 -->

---------
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent f1285cec
import Page from './page'
import './missing.css'
// This reference back to the page puts the graph's explicit entry in a cycle.
void Page
export const message = 'module graph cycle'
import type { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { message } from './dependency'
export default function Page() {
return <p>{message}</p>
}
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {}
export default nextConfig
import { nextTestSetup } from 'e2e-utils'
describe('turbopack-module-graph-cycle', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
})
it('reports compilation issues for a module cycle without panicking', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).toBe(1)
expect(cliOutput).toContain("Can't resolve './missing.css'")
expect(cliOutput).not.toContain('there must be a path to a root')
expect(cliOutput).not.toContain('Module graph is missing an entry point')
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment