Skip to content

Commit

Permalink
Revert "Error in build for middleware when import client-only (#65792)"
Browse files Browse the repository at this point in the history
This reverts commit fdd8f0c.
  • Loading branch information
ijjk committed May 21, 2024
1 parent 7fbc5f1 commit 2b3818d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ export default async function getBaseWebpackConfig(
// This will cause some performance overhead but
// acceptable as Babel will not be recommended.
getSwcLoader({
serverComponents: true,
serverComponents: false,
bundleLayer: WEBPACK_LAYERS.middleware,
}),
babelLoader,
Expand Down
13 changes: 10 additions & 3 deletions test/e2e/module-layer/module-layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,22 @@ describe('module layer', () => {
.replace("// import './lib/mixed-lib'", "import './lib/mixed-lib'")
)

const existingCliOutputLength = next.cliOutput.length
await retry(async () => {
expect(await hasRedbox(browser)).toBe(true)
const source = await getRedboxSource(browser)
expect(source).toContain(
isTurbopack
? `'client-only' cannot be imported from a Server Component module. It should only be used from a Client Component.`
: `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"`
`'client-only' cannot be imported from a Server Component module. It should only be used from a Client Component.`
)
})

if (!isTurbopack) {
const newCliOutput = next.cliOutput.slice(existingCliOutputLength)
expect(newCliOutput).toContain('./middleware.js')
expect(newCliOutput).toContain(
`'client-only' cannot be imported from a Server Component module. It should only be used from a Client Component`
)
}
})
})
}
Expand Down

0 comments on commit 2b3818d

Please sign in to comment.