Unverified Commit 1287f9a0 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: show specific SWC error messages as error titles (#91022)

### What?

Changes Turbopack's error overlay to show specific SWC diagnostic
messages as the error title instead of generic messages like "Parsing
ecmascript source code failed" or "Ecmascript file had an error".

### Why?

Previously, all SWC parse/analysis errors in Turbopack showed a generic
title (e.g. "Parsing ecmascript source code failed") in the redbox
header, with the actual specific error message buried in the description
below the code frame. This made it harder for developers to quickly
understand what went wrong.

**Before:**
```
Parsing ecmascript source code failed
> 1 | export default () => <div/
    |                           ^
Expected '>', got '<eof>'
```

**After:**
```
Expected '>', got '<eof>'
> 1 | export default () => <div/
    |                           ^
Parsing ecmascript source code failed
```

### How?

**Core change** in
`turbopack/crates/turbopack-swc-utils/src/emitter.rs`:

When the `IssueEmitter` has a `self.title` set (the generic title like
"Parsing ecmascript source code failed"), the SWC diagnostic message is
now used as the issue title, and the generic title is demoted to the
description. When `self.title` is not set, the existing behavior is
preserved (first line of message becomes title, rest becomes
description).

**Test updates** across ~15 test files:

Updated all `isTurbopack` branches in test expectations to reflect the
swapped title/description. Only Turbopack-specific branches were
modified; webpack and rspack expectations are unchanged.

**New test suite** (`test/development/app-dir/ecmascript-error-title/`):

Dedicated tests verifying that both syntax errors (e.g. `Expected '>',
got '<eof>'`) and analysis errors (e.g. `the name 'Table' is defined
multiple times`) show the specific SWC message as the redbox title.

**Turbopack snapshot updates:**

4 snapshot files renamed to reflect new titles (e.g. `Parsing ecmascript
source code failed-*.txt` → `Expression expected-*.txt`).

---------
Co-authored-by: 's avatarClaude <noreply@anthropic.com>
parent 34d0bcb9
...@@ -281,11 +281,11 @@ describe('ReactRefreshLogBox app', () => { ...@@ -281,11 +281,11 @@ describe('ReactRefreshLogBox app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:1) "source": "./index.js (7:1)
Parsing ecmascript source code failed Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
> 7 | } > 7 | }
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -34,11 +34,11 @@ describe('ReactRefreshLogBox app', () => { ...@@ -34,11 +34,11 @@ describe('ReactRefreshLogBox app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Ecmascript file had an error", "description": ""getStaticProps" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.js (3:23) "source": "./app/page.js (3:23)
Ecmascript file had an error "getStaticProps" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching
> 3 | export async function getStaticProps() { > 3 | export async function getStaticProps() {
| ^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^",
"stack": [], "stack": [],
......
...@@ -43,11 +43,11 @@ describe('Error recovery app', () => { ...@@ -43,11 +43,11 @@ describe('Error recovery app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '>', got '<eof>'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (1:27) "source": "./index.js (1:27)
Parsing ecmascript source code failed Expected '>', got '<eof>'
> 1 | export default () => <div/ > 1 | export default () => <div/
| ^", | ^",
"stack": [], "stack": [],
...@@ -136,11 +136,11 @@ describe('Error recovery app', () => { ...@@ -136,11 +136,11 @@ describe('Error recovery app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '}', got '<eof>'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/server/page.js (2:28) "source": "./app/server/page.js (2:28)
Parsing ecmascript source code failed Expected '}', got '<eof>'
> 2 | return <p>Hello world</p> > 2 | return <p>Hello world</p>
| ^", | ^",
"stack": [], "stack": [],
...@@ -220,11 +220,11 @@ describe('Error recovery app', () => { ...@@ -220,11 +220,11 @@ describe('Error recovery app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '}', got '<eof>'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/client/page.js (2:28) "source": "./app/client/page.js (2:28)
Parsing ecmascript source code failed Expected '}', got '<eof>'
> 2 | return <p>Hello world</p> > 2 | return <p>Hello world</p>
| ^", | ^",
"stack": [], "stack": [],
...@@ -655,11 +655,11 @@ describe('Error recovery app', () => { ...@@ -655,11 +655,11 @@ describe('Error recovery app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '}', got '<eof>'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (10:42) "source": "./index.js (10:42)
Parsing ecmascript source code failed Expected '}', got '<eof>'
> 10 | export default function FunctionNamed() { > 10 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
...@@ -715,11 +715,11 @@ describe('Error recovery app', () => { ...@@ -715,11 +715,11 @@ describe('Error recovery app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '}', got '<eof>'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (10:42) "source": "./index.js (10:42)
Parsing ecmascript source code failed Expected '}', got '<eof>'
> 10 | export default function FunctionNamed() { > 10 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
...@@ -907,11 +907,11 @@ describe('Error recovery app', () => { ...@@ -907,11 +907,11 @@ describe('Error recovery app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '{', got 'return'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (5:5) "source": "./index.js (5:5)
Parsing ecmascript source code failed Expected '{', got 'return'
> 5 | return <h1>Default Export</h1>; > 5 | return <h1>Default Export</h1>;
| ^^^^^^", | ^^^^^^",
"stack": [], "stack": [],
...@@ -990,11 +990,11 @@ describe('Error recovery app', () => { ...@@ -990,11 +990,11 @@ describe('Error recovery app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '{', got 'throw'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (5:5) "source": "./index.js (5:5)
Parsing ecmascript source code failed Expected '{', got 'throw'
> 5 | throw new Error('nooo'); > 5 | throw new Error('nooo');
| ^^^^^", | ^^^^^",
"stack": [], "stack": [],
...@@ -1116,11 +1116,11 @@ describe('Error recovery app', () => { ...@@ -1116,11 +1116,11 @@ describe('Error recovery app', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '}', got '<eof>'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.js (1:4) "source": "./app/page.js (1:4)
Parsing ecmascript source code failed Expected '}', got '<eof>'
> 1 | {{{ > 1 | {{{
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -176,15 +176,15 @@ describe('Error overlay - RSC build errors', () => { ...@@ -176,15 +176,15 @@ describe('Error overlay - RSC build errors', () => {
// turbopack emits the resolve issue first instead of the transform issue. // turbopack emits the resolve issue first instead of the transform issue.
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./app/server-with-errors/client-only-in-server/client-only-lib.js (1:1) "./app/server-with-errors/client-only-in-server/client-only-lib.js (1:1)
Ecmascript file had an error You're importing a component that imports client-only. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering
> 1 | import 'client-only' > 1 | import 'client-only'
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
2 | 2 |
3 | export default function ClientOnlyLib() { 3 | export default function ClientOnlyLib() {
4 | return 'client-only-lib' 4 | return 'client-only-lib'
You're importing a component that imports client-only. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default. Ecmascript file had an error
Learn more: https://nextjs.org/docs/app/building-your-application/rendering
Import trace: Import trace:
Server Component: Server Component:
...@@ -423,12 +423,12 @@ describe('Error overlay - RSC build errors', () => { ...@@ -423,12 +423,12 @@ describe('Error overlay - RSC build errors', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./app/server-with-errors/error-file/error.js (1:1) "./app/server-with-errors/error-file/error.js (1:1)
Ecmascript file had an error app/server-with-errors/error-file/error.js must be a Client Component. Add the "use client" directive the top of the file to resolve this issue.
Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
> 1 | export default function Error() {} > 1 | export default function Error() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/server-with-errors/error-file/error.js must be a Client Component. Add the "use client" directive the top of the file to resolve this issue. Ecmascript file had an error"
Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client"
`) `)
} else { } else {
await expect(session.getRedboxSource()).resolves.toMatch( await expect(session.getRedboxSource()).resolves.toMatch(
......
...@@ -108,11 +108,11 @@ describe('ReactRefreshLogBox _app _document', () => { ...@@ -108,11 +108,11 @@ describe('ReactRefreshLogBox _app _document', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expression expected",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./pages/_app.js (2:10) "source": "./pages/_app.js (2:10)
Parsing ecmascript source code failed Expression expected
> 2 | return <<Component {...pageProps} />; > 2 | return <<Component {...pageProps} />;
| ^^", | ^^",
"stack": [], "stack": [],
...@@ -227,11 +227,11 @@ describe('ReactRefreshLogBox _app _document', () => { ...@@ -227,11 +227,11 @@ describe('ReactRefreshLogBox _app _document', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./pages/_document.js (3:36) "source": "./pages/_document.js (3:36)
Parsing ecmascript source code failed Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key
> 3 | class MyDocument extends Document {{ > 3 | class MyDocument extends Document {{
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -447,11 +447,11 @@ describe('ReactRefreshLogBox', () => { ...@@ -447,11 +447,11 @@ describe('ReactRefreshLogBox', () => {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:1) "source": "./index.js (7:1)
Parsing ecmascript source code failed Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
> 7 | } > 7 | }
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -45,11 +45,11 @@ describe('pages/ error recovery', () => { ...@@ -45,11 +45,11 @@ describe('pages/ error recovery', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '>', got '<eof>'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (1:27) "source": "./index.js (1:27)
Parsing ecmascript source code failed Expected '>', got '<eof>'
> 1 | export default () => <div/ > 1 | export default () => <div/
| ^", | ^",
"stack": [], "stack": [],
...@@ -403,11 +403,11 @@ describe('pages/ error recovery', () => { ...@@ -403,11 +403,11 @@ describe('pages/ error recovery', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '{', got 'return'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (5:5) "source": "./index.js (5:5)
Parsing ecmascript source code failed Expected '{', got 'return'
> 5 | return <h1>Default Export</h1>; > 5 | return <h1>Default Export</h1>;
| ^^^^^^", | ^^^^^^",
"stack": [], "stack": [],
...@@ -487,11 +487,11 @@ describe('pages/ error recovery', () => { ...@@ -487,11 +487,11 @@ describe('pages/ error recovery', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '{', got 'throw'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (5:5) "source": "./index.js (5:5)
Parsing ecmascript source code failed Expected '{', got 'throw'
> 5 | throw new Error('nooo'); > 5 | throw new Error('nooo');
| ^^^^^", | ^^^^^",
"stack": [], "stack": [],
...@@ -821,11 +821,11 @@ describe('pages/ error recovery', () => { ...@@ -821,11 +821,11 @@ describe('pages/ error recovery', () => {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '}', got '<eof>'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:42) "source": "./index.js (7:42)
Parsing ecmascript source code failed Expected '}', got '<eof>'
> 7 | export default function FunctionNamed() { > 7 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
...@@ -886,11 +886,11 @@ describe('pages/ error recovery', () => { ...@@ -886,11 +886,11 @@ describe('pages/ error recovery', () => {
// TODO: Remove this branching once import traces are implemented in Turbopack // TODO: Remove this branching once import traces are implemented in Turbopack
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '}', got '<eof>'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:42) "source": "./index.js (7:42)
Parsing ecmascript source code failed Expected '}', got '<eof>'
> 7 | export default function FunctionNamed() { > 7 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -55,14 +55,14 @@ describe('Error Overlay for server components compiler errors in pages', () => { ...@@ -55,14 +55,14 @@ describe('Error Overlay for server components compiler errors in pages', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/Comp.js (1:1) "./components/Comp.js (1:1)
Ecmascript file had an error You're importing a component that needs "next/headers". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
> 1 | import { cookies } from 'next/headers' > 1 | import { cookies } from 'next/headers'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 | 2 |
3 | export default function Page() { 3 | export default function Page() {
4 | return <p>hello world</p> 4 | return <p>hello world</p>
You're importing a component that needs "next/headers". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components Ecmascript file had an error
Import traces: Import traces:
Browser: Browser:
...@@ -138,14 +138,14 @@ describe('Error Overlay for server components compiler errors in pages', () => { ...@@ -138,14 +138,14 @@ describe('Error Overlay for server components compiler errors in pages', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/Comp.js (1:1) "./components/Comp.js (1:1)
Ecmascript file had an error You're importing a component that needs "server-only". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
> 1 | import 'server-only' > 1 | import 'server-only'
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
2 | 2 |
3 | export default function Page() { 3 | export default function Page() {
4 | return 'hello world' 4 | return 'hello world'
You're importing a component that needs "server-only". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components Ecmascript file had an error
Import traces: Import traces:
Browser: Browser:
...@@ -223,14 +223,14 @@ describe('Error Overlay for server components compiler errors in pages', () => { ...@@ -223,14 +223,14 @@ describe('Error Overlay for server components compiler errors in pages', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/Comp.js (1:10) "./components/Comp.js (1:10)
Ecmascript file had an error You're importing a component that needs "after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
> 1 | import { after } from 'next/server' > 1 | import { after } from 'next/server'
| ^^^^^ | ^^^^^
2 | 2 |
3 | export default function Page() { 3 | export default function Page() {
4 | return 'hello world' 4 | return 'hello world'
You're importing a component that needs "after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components Ecmascript file had an error
Import traces: Import traces:
Browser: Browser:
...@@ -317,14 +317,14 @@ describe('Error Overlay for server components compiler errors in pages', () => { ...@@ -317,14 +317,14 @@ describe('Error Overlay for server components compiler errors in pages', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/Comp.js (1:1) "./components/Comp.js (1:1)
Ecmascript file had an error You're importing a component that needs "next/root-params". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
> 1 | import { foo } from 'next/root-params' > 1 | import { foo } from 'next/root-params'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 | 2 |
3 | export default function Page() { 3 | export default function Page() {
4 | return 'hello world' 4 | return 'hello world'
You're importing a component that needs "next/root-params". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components Ecmascript file had an error
Import traces: Import traces:
Browser: Browser:
......
...@@ -141,11 +141,11 @@ describe('Cache Components Dev Errors', () => { ...@@ -141,11 +141,11 @@ describe('Cache Components Dev Errors', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Ecmascript file had an error", "description": "Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.tsx (1:14) "source": "./app/page.tsx (1:14)
Ecmascript file had an error Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.
> 1 | export const revalidate = 10 > 1 | export const revalidate = 10
| ^^^^^^^^^^", | ^^^^^^^^^^",
"stack": [], "stack": [],
......
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
export function Table() {
return <p>table</p>
}
import { nextTestSetup } from 'e2e-utils'
import {
getRedboxDescription,
getRedboxSource,
waitForRedbox,
} from 'next-test-utils'
import { outdent } from 'outdent'
describe('ecmascript-error-title', () => {
const { next, isTurbopack } = nextTestSetup({
files: __dirname,
})
it('should show the specific SWC error message as title for syntax errors', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('p').text()).toBe('hello world')
await next.patchFile(
'app/page.tsx',
outdent`
export default () => <div/
`
)
if (isTurbopack) {
// The redbox description should show the specific SWC error message
// instead of the generic "Parsing ecmascript source code failed".
await waitForRedbox(browser)
const description = await getRedboxDescription(browser)
expect(description).toBe("Expected '>', got '<eof>'")
const source = await getRedboxSource(browser)
expect(source).toContain("Expected '>', got '<eof>'")
expect(source).toContain('> 1 | export default () => <div/')
}
})
it('should show the specific SWC error message as title for analysis errors', async () => {
const browser = await next.browser('/')
await next.patchFile(
'app/page.tsx',
outdent`
import { Table } from './table'
export default function Page() {
return <Table />
}
export function Table() {
return <p>hello</p>
}
`
)
if (isTurbopack) {
// The redbox description should show the specific SWC error message
// instead of the generic "Ecmascript file had an error".
await waitForRedbox(browser)
const description = await getRedboxDescription(browser)
expect(description).toBe('the name `Table` is defined multiple times')
const source = await getRedboxSource(browser)
expect(source).toContain('the name `Table` is defined multiple times')
expect(source).toContain('> 5 | export function Table() {')
}
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
...@@ -20,11 +20,11 @@ describe('app-dir - server-component-next-dynamic-ssr-false', () => { ...@@ -20,11 +20,11 @@ describe('app-dir - server-component-next-dynamic-ssr-false', () => {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
`"Ecmascript file had an error"` `"\`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a Client Component."`
) )
expect(redbox.source).toMatchInlineSnapshot(` expect(redbox.source).toMatchInlineSnapshot(`
"./app/page.js (3:23) "./app/page.js (3:23)
Ecmascript file had an error \`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a Client Component.
1 | import dynamic from 'next/dynamic' 1 | import dynamic from 'next/dynamic'
2 | 2 |
> 3 | const DynamicClient = dynamic(() => import('./client'), { ssr: false }) > 3 | const DynamicClient = dynamic(() => import('./client'), { ssr: false })
...@@ -33,7 +33,7 @@ describe('app-dir - server-component-next-dynamic-ssr-false', () => { ...@@ -33,7 +33,7 @@ describe('app-dir - server-component-next-dynamic-ssr-false', () => {
5 | export default function Page() { 5 | export default function Page() {
6 | return <DynamicClient /> 6 | return <DynamicClient />
\`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a Client Component." Ecmascript file had an error"
`) `)
} else if (process.env.NEXT_RSPACK) { } else if (process.env.NEXT_RSPACK) {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
......
...@@ -179,11 +179,12 @@ describe('react-dom/server in React Server environment', () => { ...@@ -179,11 +179,12 @@ describe('react-dom/server in React Server environment', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Ecmascript file had an error", "description": "You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/exports/app-code/react-dom-server-edge-implicit/page.js (3:1) "source": "./app/exports/app-code/react-dom-server-edge-implicit/page.js (3:1)
Ecmascript file had an error You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering
> 3 | import ReactDOMServerEdgeDefault from 'react-dom/server' > 3 | import ReactDOMServerEdgeDefault from 'react-dom/server'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
"stack": [], "stack": [],
...@@ -322,9 +323,10 @@ describe('react-dom/server in React Server environment', () => { ...@@ -322,9 +323,10 @@ describe('react-dom/server in React Server environment', () => {
if (isTurbopack) { if (isTurbopack) {
expect(redbox).toMatchInlineSnapshot(` expect(redbox).toMatchInlineSnapshot(`
{ {
"description": "Ecmascript file had an error", "description": "You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.",
"source": "./app/exports/app-code/react-dom-server-node-implicit/page.js (3:1) "source": "./app/exports/app-code/react-dom-server-node-implicit/page.js (3:1)
Ecmascript file had an error You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering
1 | import * as ReactDOMServerNode from 'react-dom/server' 1 | import * as ReactDOMServerNode from 'react-dom/server'
2 | // Fine to drop once React is on ESM 2 | // Fine to drop once React is on ESM
> 3 | import ReactDOMServerNodeDefault from 'react-dom/server' > 3 | import ReactDOMServerNodeDefault from 'react-dom/server'
...@@ -333,8 +335,7 @@ describe('react-dom/server in React Server environment', () => { ...@@ -333,8 +335,7 @@ describe('react-dom/server in React Server environment', () => {
5 | export const runtime = 'nodejs' 5 | export const runtime = 'nodejs'
6 | 6 |
You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security. Ecmascript file had an error",
Learn more: https://nextjs.org/docs/app/building-your-application/rendering",
} }
`) `)
} else if (isRspack) { } else if (isRspack) {
......
...@@ -164,14 +164,14 @@ export function runErrorRecoveryHmrTest(nextConfig: { ...@@ -164,14 +164,14 @@ export function runErrorRecoveryHmrTest(nextConfig: {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(source).toMatchInlineSnapshot(` expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js (7:1) "./pages/hmr/about2.js (7:1)
Parsing ecmascript source code failed Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
5 | div 5 | div
6 | ) 6 | )
> 7 | } > 7 | }
| ^ | ^
8 | 8 |
Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?" Parsing ecmascript source code failed"
`) `)
} else if (process.env.NEXT_RSPACK) { } else if (process.env.NEXT_RSPACK) {
expect(trimEndMultiline(source)).toMatchInlineSnapshot(` expect(trimEndMultiline(source)).toMatchInlineSnapshot(`
...@@ -514,7 +514,7 @@ export function runErrorRecoveryHmrTest(nextConfig: { ...@@ -514,7 +514,7 @@ export function runErrorRecoveryHmrTest(nextConfig: {
expect(next.normalizeTestDirContent(redboxSource)) expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/parse-error.js (3:1) "./components/parse-error.js (3:1)
Parsing ecmascript source code failed Expression expected
1 | This 1 | This
2 | is 2 | is
> 3 | }}} > 3 | }}}
...@@ -522,7 +522,7 @@ export function runErrorRecoveryHmrTest(nextConfig: { ...@@ -522,7 +522,7 @@ export function runErrorRecoveryHmrTest(nextConfig: {
4 | invalid 4 | invalid
5 | js 5 | js
Expression expected Parsing ecmascript source code failed
Import traces: Import traces:
Browser: Browser:
......
...@@ -501,11 +501,11 @@ describe('middleware - development errors', () => { ...@@ -501,11 +501,11 @@ describe('middleware - development errors', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '{', got '}'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./middleware.js (1:28) "source": "./middleware.js (1:28)
Parsing ecmascript source code failed Expected '{', got '}'
> 1 | export default function () } > 1 | export default function () }
| ^", | ^",
"stack": [], "stack": [],
...@@ -586,11 +586,11 @@ describe('middleware - development errors', () => { ...@@ -586,11 +586,11 @@ describe('middleware - development errors', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Parsing ecmascript source code failed", "description": "Expected '{', got '}'",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./middleware.js (1:28) "source": "./middleware.js (1:28)
Parsing ecmascript source code failed Expected '{', got '}'
> 1 | export default function () } > 1 | export default function () }
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -34,7 +34,7 @@ describe('cache-components-route-handler-errors', () => { ...@@ -34,7 +34,7 @@ describe('cache-components-route-handler-errors', () => {
if (isTurbopack) { if (isTurbopack) {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
`"Ecmascript file had an error"` `"Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."`
) )
} else { } else {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
......
...@@ -2,11 +2,22 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,11 +2,22 @@ import { nextTestSetup } from 'e2e-utils'
import { waitForRedbox } from 'next-test-utils' import { waitForRedbox } from 'next-test-utils'
// Filter out browser log lines from CLI output to avoid counting forwarded browser errors // Filter CLI output to only keep Turbopack error header lines (starting with ⨯ or
function filterBrowserLogs(output: string): string { // standalone file:line:col) to accurately count error occurrences without counting
// console.error, stack traces, or forwarded browser logs.
function filterToErrorHeaders(output: string): string {
return output return output
.split('\n') .split('\n')
.filter((line) => !line.includes('[browser]')) .filter(
(line) =>
!line.includes('[browser]') &&
!line.includes('console.error') &&
!line.includes('at <unknown>') &&
!line.includes('at Object.') &&
!line.includes('at DevServer.') &&
!line.includes('at DevBundlerService.') &&
!line.includes('at async ')
)
.join('\n') .join('\n')
} }
...@@ -37,12 +48,12 @@ function filterBrowserLogs(output: string): string { ...@@ -37,12 +48,12 @@ function filterBrowserLogs(output: string): string {
waitForRedbox(browser) waitForRedbox(browser)
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Ecmascript file had an error", "description": "Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/edge-with-layout/edge/page.tsx (1:14) "source": "./app/edge-with-layout/layout.tsx (1:14)
Ecmascript file had an error Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.
> 1 | export const runtime = 'edge' > 1 | export const dynamic = 'force-dynamic'
| ^^^^^^^", | ^^^^^^^",
"stack": [], "stack": [],
} }
...@@ -50,7 +61,7 @@ function filterBrowserLogs(output: string): string { ...@@ -50,7 +61,7 @@ function filterBrowserLogs(output: string): string {
// Count occurrences of the layout error at the specific location // Count occurrences of the layout error at the specific location
// Filter out browser logs to avoid counting forwarded browser errors // Filter out browser logs to avoid counting forwarded browser errors
const filteredOutput = filterBrowserLogs(next.cliOutput) const filteredOutput = filterToErrorHeaders(next.cliOutput)
const layoutErrorMatches = filteredOutput.match( const layoutErrorMatches = filteredOutput.match(
/\.\/app\/edge-with-layout\/layout\.tsx:1:14/g /\.\/app\/edge-with-layout\/layout\.tsx:1:14/g
) )
......
...@@ -34,7 +34,7 @@ describe('cache-components-segment-configs', () => { ...@@ -34,7 +34,7 @@ describe('cache-components-segment-configs', () => {
if (isTurbopack) { if (isTurbopack) {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
`"Ecmascript file had an error"` `"Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."`
) )
} else { } else {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
...@@ -94,8 +94,10 @@ describe('cache-components-segment-configs', () => { ...@@ -94,8 +94,10 @@ describe('cache-components-segment-configs', () => {
} }
if (isTurbopack) { if (isTurbopack) {
// The page-level error is shown first in the redbox, but
// the layout error is also present in the CLI output.
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
`"Ecmascript file had an error"` `"Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."`
) )
} else { } else {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
...@@ -103,6 +105,12 @@ describe('cache-components-segment-configs', () => { ...@@ -103,6 +105,12 @@ describe('cache-components-segment-configs', () => {
) )
} }
expect(redbox.source).toContain( expect(redbox.source).toContain(
'is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
// Verify that the "runtime" error from the layout propagation
// is present in the CLI output even if it's not the first error
// shown in the redbox.
expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
) )
} else { } else {
......
...@@ -26,7 +26,8 @@ describe('app-dir - error-on-next-codemod-comment', () => { ...@@ -26,7 +26,8 @@ describe('app-dir - error-on-next-codemod-comment', () => {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(` expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./app/page.tsx (2:2) "./app/page.tsx (2:2)
Ecmascript file had an error You have an unresolved @next/codemod comment "remove jsx of next line" that needs review.
After review, either remove the comment if you made the necessary changes or replace "@next-codemod-error" with "@next-codemod-ignore" to bypass the build error if no action at this line can be taken.
1 | export default function Page() { 1 | export default function Page() {
> 2 | // @next-codemod-error remove jsx of next line > 2 | // @next-codemod-error remove jsx of next line
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -34,8 +35,7 @@ describe('app-dir - error-on-next-codemod-comment', () => { ...@@ -34,8 +35,7 @@ describe('app-dir - error-on-next-codemod-comment', () => {
4 | } 4 | }
5 | 5 |
You have an unresolved @next/codemod comment "remove jsx of next line" that needs review. Ecmascript file had an error"
After review, either remove the comment if you made the necessary changes or replace "@next-codemod-error" with "@next-codemod-ignore" to bypass the build error if no action at this line can be taken."
`) `)
} else if (process.env.NEXT_RSPACK) { } else if (process.env.NEXT_RSPACK) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(` expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
......
...@@ -22,11 +22,11 @@ describe('use-cache-segment-configs', () => { ...@@ -22,11 +22,11 @@ describe('use-cache-segment-configs', () => {
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": "Ecmascript file had an error", "description": "Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it.",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/runtime/page.tsx (1:14) "source": "./app/runtime/page.tsx (1:14)
Ecmascript file had an error Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it.
> 1 | export const runtime = 'edge' > 1 | export const runtime = 'edge'
| ^^^^^^^", | ^^^^^^^",
"stack": [], "stack": [],
...@@ -80,14 +80,14 @@ describe('use-cache-segment-configs', () => { ...@@ -80,14 +80,14 @@ describe('use-cache-segment-configs', () => {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
"Error: Turbopack build failed with 1 errors: "Error: Turbopack build failed with 1 errors:
./app/runtime/page.tsx:1:14 ./app/runtime/page.tsx:1:14
Ecmascript file had an error Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it.
> 1 | export const runtime = 'edge' > 1 | export const runtime = 'edge'
| ^^^^^^^ | ^^^^^^^
2 | 2 |
3 | export default function Page() { 3 | export default function Page() {
4 | return <div>This page uses \`export const runtime\`.</div> 4 | return <div>This page uses \`export const runtime\`.</div>
Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Ecmascript file had an error
at <unknown> (./app/runtime/page.tsx:1:14) at <unknown> (./app/runtime/page.tsx:1:14)
......
...@@ -32,15 +32,14 @@ describe('use-cache-unknown-cache-kind', () => { ...@@ -32,15 +32,14 @@ describe('use-cache-unknown-cache-kind', () => {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
"Error: Turbopack build failed with 1 errors: "Error: Turbopack build failed with 1 errors:
./app/page.tsx:1:1 ./app/page.tsx:1:1
Ecmascript file had an error Unknown cache kind "custom". Please configure a cache handler for this kind in the \`cacheHandlers\` object in your Next.js config.
> 1 | 'use cache: custom' > 1 | 'use cache: custom'
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
2 | 2 |
3 | export default async function Page() { 3 | export default async function Page() {
4 | return <p>hello world</p> 4 | return <p>hello world</p>
Unknown cache kind "custom". Please configure a cache handler for this kind in the \`cacheHandlers\` object in your Next.js config. Ecmascript file had an error
at <unknown> (./app/page.tsx:1:1) at <unknown> (./app/page.tsx:1:1)
...@@ -113,7 +112,7 @@ describe('use-cache-unknown-cache-kind', () => { ...@@ -113,7 +112,7 @@ describe('use-cache-unknown-cache-kind', () => {
if (isTurbopack) { if (isTurbopack) {
expect(errorDescription).toMatchInlineSnapshot( expect(errorDescription).toMatchInlineSnapshot(
`"Ecmascript file had an error"` `"Unknown cache kind "custom". Please configure a cache handler for this kind in the \`cacheHandlers\` object in your Next.js config."`
) )
} else if (isRspack) { } else if (isRspack) {
expect(errorDescription).toMatchInlineSnapshot( expect(errorDescription).toMatchInlineSnapshot(
...@@ -128,14 +127,14 @@ describe('use-cache-unknown-cache-kind', () => { ...@@ -128,14 +127,14 @@ describe('use-cache-unknown-cache-kind', () => {
if (isTurbopack) { if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
"./app/page.tsx (1:1) "./app/page.tsx (1:1)
Ecmascript file had an error Unknown cache kind "custom". Please configure a cache handler for this kind in the \`cacheHandlers\` object in your Next.js config.
> 1 | 'use cache: custom' > 1 | 'use cache: custom'
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
2 | 2 |
3 | export default async function Page() { 3 | export default async function Page() {
4 | return <p>hello world</p> 4 | return <p>hello world</p>
Unknown cache kind "custom". Please configure a cache handler for this kind in the \`cacheHandlers\` object in your Next.js config." Ecmascript file had an error"
`) `)
} else if (isRspack) { } else if (isRspack) {
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
......
...@@ -30,25 +30,16 @@ describe('use-cache-without-experimental-flag', () => { ...@@ -30,25 +30,16 @@ describe('use-cache-without-experimental-flag', () => {
const buildOutput = getBuildOutput(cliOutput) const buildOutput = getBuildOutput(cliOutput)
if (isTurbopack) { if (isTurbopack) {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toContain(
"Error: Turbopack build failed with 1 errors: 'To use "use cache", please enable the feature flag `cacheComponents` in your Next.js config.'
./app/page.tsx:1:1 )
Ecmascript file had an error expect(buildOutput).toContain(
> 1 | 'use cache' 'Read more: https://nextjs.org/docs/canary/app/api-reference/directives/use-cache#usage'
| ^^^^^^^^^^^ )
2 | expect(buildOutput).toContain('Ecmascript file had an error')
3 | export default async function Page() { expect(buildOutput).toContain('./app/page.tsx:1:1')
4 | return <p>hello world</p> expect(buildOutput).toContain("> 1 | 'use cache'")
expect(buildOutput).toContain('at <unknown> (./app/page.tsx:1:1)')
To use "use cache", please enable the feature flag \`cacheComponents\` in your Next.js config.
Read more: https://nextjs.org/docs/canary/app/api-reference/directives/use-cache#usage
at <unknown> (./app/page.tsx:1:1)
"
`)
} else if (isRspack) { } else if (isRspack) {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
" "
...@@ -109,7 +100,7 @@ describe('use-cache-without-experimental-flag', () => { ...@@ -109,7 +100,7 @@ describe('use-cache-without-experimental-flag', () => {
if (isTurbopack) { if (isTurbopack) {
expect(errorDescription).toMatchInlineSnapshot( expect(errorDescription).toMatchInlineSnapshot(
`"Ecmascript file had an error"` `"To use "use cache", please enable the feature flag \`cacheComponents\` in your Next.js config."`
) )
} else if (isRspack) { } else if (isRspack) {
expect(errorDescription).toMatchInlineSnapshot( expect(errorDescription).toMatchInlineSnapshot(
...@@ -122,19 +113,15 @@ describe('use-cache-without-experimental-flag', () => { ...@@ -122,19 +113,15 @@ describe('use-cache-without-experimental-flag', () => {
} }
if (isTurbopack) { if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toContain('./app/page.tsx (1:1)')
"./app/page.tsx (1:1) expect(errorSource).toContain(
Ecmascript file had an error 'To use "use cache", please enable the feature flag `cacheComponents` in your Next.js config.'
> 1 | 'use cache' )
| ^^^^^^^^^^^ expect(errorSource).toContain(
2 | 'Read more: https://nextjs.org/docs/canary/app/api-reference/directives/use-cache#usage'
3 | export default async function Page() { )
4 | return <p>hello world</p> expect(errorSource).toContain("> 1 | 'use cache'")
expect(errorSource).toContain('Ecmascript file had an error')
To use "use cache", please enable the feature flag \`cacheComponents\` in your Next.js config.
Read more: https://nextjs.org/docs/canary/app/api-reference/directives/use-cache#usage"
`)
} else if (isRspack) { } else if (isRspack) {
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
"./app/page.tsx "./app/page.tsx
......
...@@ -136,9 +136,15 @@ impl Emitter for IssueEmitter { ...@@ -136,9 +136,15 @@ impl Emitter for IssueEmitter {
} }
}; };
// When self.title is set (e.g. "Parsing ecmascript source code failed"),
// use the SWC diagnostic as the title for a more specific error message,
// and demote the generic title to the description.
// When self.title is not set, use the first line of the message as title
// and the rest as description.
let title; let title;
if let Some(t) = self.title.as_ref() { if let Some(t) = self.title.as_ref() {
title = t.clone(); title = message.trim().into();
message = t.to_string();
} else { } else {
let mut message_split = message.split('\n'); let mut message_split = message.split('\n');
title = message_split.next().unwrap().trim().to_string().into(); title = message_split.next().unwrap().trim().to_string().into();
......
error - [analysis] /turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/invalid-export-parse-error/input/invalid-export/broken.js:3:0 Parsing ecmascript source code failed error - [analysis] /turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/invalid-export-parse-error/input/invalid-export/broken.js:3:0 Expression expected
1 | export const a = 42 1 | export const a = 42
2 | export const b = 2 | export const b =
+ v + v
3 + 3 +
+ ^ + ^
Expression expected Parsing ecmascript source code failed
Import trace: Import trace:
test: test:
......
error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/other.ts:2:7 Parsing ecmascript source code failed error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/other.ts:2:7 Cannot assign to this
1 | function x() { 1 | function x() {
+ v + v
2 + ;[1, 2] = [1, 2] 2 + ;[1, 2] = [1, 2]
...@@ -8,7 +8,7 @@ error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-par ...@@ -8,7 +8,7 @@ error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-par
5 | console.log(x()); 5 | console.log(x());
6 | 6 |
Cannot assign to this Parsing ecmascript source code failed
Import trace: Import trace:
test: test:
......
error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/other.ts:2:4 Parsing ecmascript source code failed error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/other.ts:2:4 Cannot assign to this
1 | function x() { 1 | function x() {
+ v + v
2 + ;[1, 2] = [1, 2] 2 + ;[1, 2] = [1, 2]
...@@ -8,7 +8,7 @@ error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-par ...@@ -8,7 +8,7 @@ error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-par
5 | console.log(x()); 5 | console.log(x());
6 | 6 |
Cannot assign to this Parsing ecmascript source code failed
Import trace: Import trace:
test: test:
......
error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/imports/duplicate-binding/input/index.js:3:16 Ecmascript file had an error error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/imports/duplicate-binding/input/index.js:3:16 the name `Table` is defined multiple times
1 | import { Table } from './table' 1 | import { Table } from './table'
2 | 2 |
+ v---v + v---v
...@@ -8,4 +8,4 @@ error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/imports/dupl ...@@ -8,4 +8,4 @@ error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/imports/dupl
5 | } 5 | }
6 | 6 |
the name `Table` is defined multiple times Ecmascript file had an error
\ No newline at end of file \ No newline at end of file
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