Skip to content

Commit

Permalink
error in build for middleware when import client-only
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed May 15, 2024
1 parent 0b261f0 commit 87f3690
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 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 @@ -509,7 +509,7 @@ export default async function getBaseWebpackConfig(
// This will cause some performance overhead but
// acceptable as Babel will not be recommended.
getSwcLoader({
serverComponents: false,
serverComponents: true,
bundleLayer: WEBPACK_LAYERS.middleware,
}),
babelLoader,
Expand Down
13 changes: 2 additions & 11 deletions test/e2e/module-layer/module-layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { nextTestSetup } from 'e2e-utils'
import { getRedboxSource, hasRedbox, retry } from 'next-test-utils'

describe('module layer', () => {
const { next, isNextStart, isNextDev, isTurbopack } = nextTestSetup({
const { next, isNextStart, isNextDev } = nextTestSetup({
files: __dirname,
})

Expand Down Expand Up @@ -81,22 +81,13 @@ 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(
`'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"`
)
})

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 87f3690

Please sign in to comment.