Unverified Commit fdd8f0c6 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Error in build for middleware when import client-only (#65792)

Follow up for #65424 

Turn on RSC server-only and client-only checking, so it can error
earlier in build
parent 81d5dadd
...@@ -509,7 +509,7 @@ export default async function getBaseWebpackConfig( ...@@ -509,7 +509,7 @@ export default async function getBaseWebpackConfig(
// This will cause some performance overhead but // This will cause some performance overhead but
// acceptable as Babel will not be recommended. // acceptable as Babel will not be recommended.
getSwcLoader({ getSwcLoader({
serverComponents: false, serverComponents: true,
bundleLayer: WEBPACK_LAYERS.middleware, bundleLayer: WEBPACK_LAYERS.middleware,
}), }),
babelLoader, babelLoader,
......
...@@ -81,22 +81,15 @@ describe('module layer', () => { ...@@ -81,22 +81,15 @@ describe('module layer', () => {
.replace("// import './lib/mixed-lib'", "import './lib/mixed-lib'") .replace("// import './lib/mixed-lib'", "import './lib/mixed-lib'")
) )
const existingCliOutputLength = next.cliOutput.length
await retry(async () => { await retry(async () => {
expect(await hasRedbox(browser)).toBe(true) expect(await hasRedbox(browser)).toBe(true)
const source = await getRedboxSource(browser) const source = await getRedboxSource(browser)
expect(source).toContain( expect(source).toContain(
`'client-only' cannot be imported from a Server Component module. It should only be used from a Client Component.` 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"`
) )
}) })
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`
)
}
}) })
}) })
} }
......
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