Unverified Commit 5b609e26 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Error on legacy runtime config under app dir (#48774)

When you're using `config` object with `runtime` we'll show a warning and recomment you to move to `export const runtime = ...` for runtime property as it's documented as recommended. This PR adds a error for `next build` to avoid logs are truncated during multi-workers build and you're aware of the config which doesn't take effect with seeing the error

Follow up for #48630
link [NEXT-426](https://linear.app/vercel/issue/NEXT-426)
parent 03f34625
......@@ -342,9 +342,12 @@ export async function getPageStaticInfo(params: {
}
if (pageType === 'app') {
if (config) {
Log.warnOnce(
`\`export const config\` in ${pageFilePath} is deprecated. Please change it to segment export config. See https://beta.nextjs.org/docs/api-reference/segment-config`
)
const message = `\`export const config\` in ${pageFilePath} is deprecated. Please change \`runtime\` property to segment export config. See https://beta.nextjs.org/docs/api-reference/segment-config`
if (isDev) {
Log.warnOnce(message)
} else {
throw new Error(message)
}
config = {}
}
}
......
/*global globalThis*/
export default function Page() {
if ('EdgeRuntime' in globalThis) {
return <p>Edge!</p>
......
import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'app-dir edge runtime config',
{
files: __dirname,
skipStart: true,
skipDeployment: true,
},
({ next, isNextDev }) => {
it('should warn the legacy object config export', async () => {
let error
await next.start().catch((err) => {
error = err
})
if (isNextDev) {
expect(error).not.toBeDefined()
await next.fetch('/legacy-runtime-config')
} else {
expect(error).toBeDefined()
}
expect(next.cliOutput).toContain('`export const config`')
expect(next.cliOutput).toContain(
'app/legacy-runtime-config/page.js is deprecated. Please change `runtime` property to segment export config. See https://beta.nextjs.org/docs/api-reference/segment-config'
)
})
}
)
module.exports = {
experimental: {
appDir: true,
},
}
......@@ -16,14 +16,6 @@ createNextDescribe(
expect(pageHtml).toContain('<p>pages-edge-ssr</p>')
})
it('should warn the legacy object config export', async () => {
await next.render('/edge/legacy')
expect(next.cliOutput).toContain('`export const config`')
expect(next.cliOutput).toContain(
'app/edge/legacy/page.tsx is deprecated. Please change it to segment export config. See https://beta.nextjs.org/docs/api-reference/segment-config'
)
})
it('should retrieve cookies in a server component in the edge runtime', async () => {
const res = await next.fetch('/edge-apis/cookies')
expect(await res.text()).toInclude('Hello')
......
......@@ -8,9 +8,7 @@ async function getData() {
}
}
export const config = {
runtime: 'nodejs',
}
export const runtime = 'nodejs'
export default function Page(props) {
const { type } = use(getData())
......
......@@ -15,6 +15,4 @@ export default function Page() {
Page.title = 'node-rsc'
export const config = {
runtime: 'nodejs',
}
export const runtime = 'nodejs'
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