Unverified Commit 3c2a1959 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Also enforce experimental features when there's no next config file (#81679)

When running `next build --debug-prerender`, we also want to set the experimental features even if there is no next.config.js file present.

This PR also fixes the `cloneObject` function to better handle nested optional object properties, and we're now also freezing and cloning the default config before applying changes to it.

> [!NOTE]  
> This PR is best reviewed with hidden whitespace changes.
parent 1a0c4d08
...@@ -1283,7 +1283,7 @@ export interface NextConfig extends Record<string, any> { ...@@ -1283,7 +1283,7 @@ export interface NextConfig extends Record<string, any> {
htmlLimitedBots?: RegExp htmlLimitedBots?: RegExp
} }
export const defaultConfig = { export const defaultConfig = Object.freeze({
env: {}, env: {},
webpack: null, webpack: null,
eslint: { eslint: {
...@@ -1503,7 +1503,7 @@ export const defaultConfig = { ...@@ -1503,7 +1503,7 @@ export const defaultConfig = {
}, },
htmlLimitedBots: undefined, htmlLimitedBots: undefined,
bundlePagesRouterDependencies: false, bundlePagesRouterDependencies: false,
} satisfies NextConfig } satisfies NextConfig)
export async function normalizeConfig(phase: string, config: any) { export async function normalizeConfig(phase: string, config: any) {
if (typeof config === 'function') { if (typeof config === 'function') {
......
...@@ -1227,6 +1227,7 @@ export default async function loadConfig( ...@@ -1227,6 +1227,7 @@ export default async function loadConfig(
} }
const path = await findUp(CONFIG_FILES, { cwd: dir }) const path = await findUp(CONFIG_FILES, { cwd: dir })
const configuredExperimentalFeatures: ConfiguredExperimentalFeature[] = []
// If config file was found // If config file was found
if (path?.length) { if (path?.length) {
...@@ -1280,8 +1281,6 @@ export default async function loadConfig( ...@@ -1280,8 +1281,6 @@ export default async function loadConfig(
)) as NextConfig )) as NextConfig
) )
const configuredExperimentalFeatures: ConfiguredExperimentalFeature[] = []
if (reportExperimentalFeatures && loadedConfig.experimental) { if (reportExperimentalFeatures && loadedConfig.experimental) {
for (const name of Object.keys( for (const name of Object.keys(
loadedConfig.experimental loadedConfig.experimental
...@@ -1420,58 +1419,13 @@ export default async function loadConfig( ...@@ -1420,58 +1419,13 @@ export default async function loadConfig(
userConfig.htmlLimitedBots = userConfig.htmlLimitedBots.source userConfig.htmlLimitedBots = userConfig.htmlLimitedBots.source
} }
if ( enforceExperimentalFeatures(userConfig, {
userConfig.experimental && configuredExperimentalFeatures: reportExperimentalFeatures
userConfig.experimental.enablePrerenderSourceMaps === undefined && ? configuredExperimentalFeatures
userConfig.experimental.dynamicIO === true : undefined,
) { debugPrerender,
userConfig.experimental.enablePrerenderSourceMaps = true phase,
addConfiguredExperimentalFeature( })
configuredExperimentalFeatures,
'enablePrerenderSourceMaps',
true,
'enabled by `experimental.dynamicIO`'
)
}
if (
debugPrerender &&
(phase === PHASE_PRODUCTION_BUILD || phase === PHASE_EXPORT)
) {
userConfig.experimental ??= {}
setExperimentalFeatureForDebugPrerender(
userConfig.experimental,
'serverSourceMaps',
true,
reportExperimentalFeatures ? configuredExperimentalFeatures : undefined
)
setExperimentalFeatureForDebugPrerender(
userConfig.experimental,
process.env.TURBOPACK ? 'turbopackMinify' : 'serverMinification',
false,
reportExperimentalFeatures ? configuredExperimentalFeatures : undefined
)
setExperimentalFeatureForDebugPrerender(
userConfig.experimental,
'enablePrerenderSourceMaps',
true,
reportExperimentalFeatures ? configuredExperimentalFeatures : undefined
)
setExperimentalFeatureForDebugPrerender(
userConfig.experimental,
'prerenderEarlyExit',
false,
reportExperimentalFeatures ? configuredExperimentalFeatures : undefined
)
}
if (reportExperimentalFeatures) {
reportExperimentalFeatures(configuredExperimentalFeatures)
}
const completeConfig = assignDefaults( const completeConfig = assignDefaults(
dir, dir,
...@@ -1483,6 +1437,11 @@ export default async function loadConfig( ...@@ -1483,6 +1437,11 @@ export default async function loadConfig(
}, },
silent silent
) as NextConfigComplete ) as NextConfigComplete
if (reportExperimentalFeatures) {
reportExperimentalFeatures(configuredExperimentalFeatures)
}
return await applyModifyConfig(completeConfig, phase, silent) return await applyModifyConfig(completeConfig, phase, silent)
} else { } else {
const configBaseName = basename(CONFIG_FILES[0], extname(CONFIG_FILES[0])) const configBaseName = basename(CONFIG_FILES[0], extname(CONFIG_FILES[0]))
...@@ -1506,14 +1465,30 @@ export default async function loadConfig( ...@@ -1506,14 +1465,30 @@ export default async function loadConfig(
} }
} }
const clonedDefaultConfig = cloneObject(defaultConfig) as NextConfig
enforceExperimentalFeatures(clonedDefaultConfig, {
configuredExperimentalFeatures: reportExperimentalFeatures
? configuredExperimentalFeatures
: undefined,
debugPrerender,
phase,
})
// always call assignDefaults to ensure settings like // always call assignDefaults to ensure settings like
// reactRoot can be updated correctly even with no next.config.js // reactRoot can be updated correctly even with no next.config.js
const completeConfig = assignDefaults( const completeConfig = assignDefaults(
dir, dir,
{ ...defaultConfig, configFileName }, { ...clonedDefaultConfig, configFileName },
silent silent
) as NextConfigComplete ) as NextConfigComplete
setHttpClientAndAgentOptions(completeConfig) setHttpClientAndAgentOptions(completeConfig)
if (reportExperimentalFeatures) {
reportExperimentalFeatures(configuredExperimentalFeatures)
}
return await applyModifyConfig(completeConfig, phase, silent) return await applyModifyConfig(completeConfig, phase, silent)
} }
...@@ -1523,7 +1498,70 @@ export type ConfiguredExperimentalFeature = { ...@@ -1523,7 +1498,70 @@ export type ConfiguredExperimentalFeature = {
reason?: string reason?: string
} }
export function addConfiguredExperimentalFeature< function enforceExperimentalFeatures(
config: NextConfig,
options: {
configuredExperimentalFeatures: ConfiguredExperimentalFeature[] | undefined
debugPrerender: boolean | undefined
phase: string
}
) {
const { configuredExperimentalFeatures, debugPrerender, phase } = options
if (
config.experimental &&
config.experimental.enablePrerenderSourceMaps === undefined &&
config.experimental.dynamicIO === true
) {
config.experimental.enablePrerenderSourceMaps = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'enablePrerenderSourceMaps',
true,
'enabled by `experimental.dynamicIO`'
)
}
}
config.experimental ??= {}
if (
debugPrerender &&
(phase === PHASE_PRODUCTION_BUILD || phase === PHASE_EXPORT)
) {
setExperimentalFeatureForDebugPrerender(
config.experimental,
'serverSourceMaps',
true,
configuredExperimentalFeatures
)
setExperimentalFeatureForDebugPrerender(
config.experimental,
process.env.TURBOPACK ? 'turbopackMinify' : 'serverMinification',
false,
configuredExperimentalFeatures
)
setExperimentalFeatureForDebugPrerender(
config.experimental,
'enablePrerenderSourceMaps',
true,
configuredExperimentalFeatures
)
setExperimentalFeatureForDebugPrerender(
config.experimental,
'prerenderEarlyExit',
false,
configuredExperimentalFeatures
)
}
}
function addConfiguredExperimentalFeature<
KeyType extends keyof ExperimentalConfig, KeyType extends keyof ExperimentalConfig,
>( >(
configuredExperimentalFeatures: ConfiguredExperimentalFeature[], configuredExperimentalFeatures: ConfiguredExperimentalFeature[],
...@@ -1564,20 +1602,50 @@ function setExperimentalFeatureForDebugPrerender< ...@@ -1564,20 +1602,50 @@ function setExperimentalFeatureForDebugPrerender<
} }
function cloneObject(obj: any): any { function cloneObject(obj: any): any {
// Primitives & null
if (obj === null || typeof obj !== 'object') { if (obj === null || typeof obj !== 'object') {
return obj return obj
} }
// RegExp → clone via constructor
if (obj instanceof RegExp) {
return new RegExp(obj.source, obj.flags)
}
// Function → just reuse the function reference
if (typeof obj === 'function') {
return obj
}
// Arrays → map each element
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
return obj.map(cloneObject) return obj.map(cloneObject)
} }
const keys = Object.keys(obj)
if (keys.length === 0) { // Detect non‑plain objects (class instances)
const proto = Object.getPrototypeOf(obj)
const isPlainObject = proto === Object.prototype || proto === null
// If it's not a plain object, just return the original
if (!isPlainObject) {
return obj return obj
} }
return keys.reduce((acc, key) => { // Plain object → create a new object with the same prototype
;(acc as any)[key] = cloneObject(obj[key]) // and copy all properties, cloning data properties and keeping
return acc // accessor properties (getters/setters) as‑is.
}, {}) const result = Object.create(proto)
for (const key of Reflect.ownKeys(obj)) {
const descriptor = Object.getOwnPropertyDescriptor(obj, key)
if (descriptor && (descriptor.get || descriptor.set)) {
// Accessor property → copy descriptor as‑is (get/set functions)
Object.defineProperty(result, key, descriptor)
} else {
// Data property → clone the value
result[key] = cloneObject(obj[key])
}
}
return result
} }
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import path from 'path'
const { version: nextVersion } = require('next/package.json') const { version: nextVersion } = require('next/package.json')
describe('build-output-prerender', () => { describe('build-output-prerender', () => {
describe('without --debug-prerender', () => { describe('with a next config file', () => {
const { next, isTurbopack } = nextTestSetup({ describe('without --debug-prerender', () => {
files: __dirname, const { next, isTurbopack } = nextTestSetup({
skipStart: true, files: path.join(__dirname, 'fixtures/with-config-file'),
}) skipStart: true,
})
beforeAll(() => next.build())
it('prints only the user-selected experimental flags', async () => {
if (isTurbopack) {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
"▲ Next.js x.y.z (Turbopack)
- Experiments (use with caution):
✓ dynamicIO
✓ enablePrerenderSourceMaps (enabled by \`experimental.dynamicIO\`)"
`)
} else {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
"▲ Next.js x.y.z
- Experiments (use with caution):
✓ dynamicIO
✓ enablePrerenderSourceMaps (enabled by \`experimental.dynamicIO\`)"
`)
}
})
beforeAll(() => next.build()) it('shows only a single prerender error with a mangled stack', async () => {
if (isTurbopack) {
it('prints only the user-selected experimental flags', async () => { // TODO(veil): Why is the location incomplete unless we enable --no-mangling?
if (isTurbopack) { expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(`
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(` "Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
"▲ Next.js x.y.z (Turbopack) at c (turbopack:///[project]/app/client/page.tsx:5:0)
- Experiments (use with caution): 3 | export default function Page() {
✓ dynamicIO 4 | return <p>Current time: {new Date().toISOString()}</p>
✓ enablePrerenderSourceMaps (enabled by \`experimental.dynamicIO\`)" > 5 | }
`) 6 |
} else { To get a more detailed stack trace and pinpoint the issue, try one of the following:
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(` - Start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error.
"▲ Next.js x.y.z - Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.
- Experiments (use with caution): Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error
✓ dynamicIO Export encountered an error on /client/page: /client, exiting the build."
✓ enablePrerenderSourceMaps (enabled by \`experimental.dynamicIO\`)" `)
`) } else {
} expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(`
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at x (<next-dist-dir>)
To get a more detailed stack trace and pinpoint the issue, try one of the following:
- Start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error.
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /client/page: /client, exiting the build."
`)
}
})
}) })
it('shows only a single prerender error with a mangled stack', async () => { describe('with --debug-prerender', () => {
if (isTurbopack) { const { next, isTurbopack } = nextTestSetup({
// TODO(veil): Why is the location incomplete unless we enable --no-mangling? files: path.join(__dirname, 'fixtures/with-config-file'),
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(` skipStart: true,
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client buildArgs: ['--debug-prerender'],
at c (turbopack:///[project]/app/client/page.tsx:5:0) })
3 | export default function Page() {
4 | return <p>Current time: {new Date().toISOString()}</p> beforeAll(() => next.build())
> 5 | }
6 | it('prints a warning and the customized experimental flags', async () => {
To get a more detailed stack trace and pinpoint the issue, try one of the following: if (isTurbopack) {
- Start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error. expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces. "⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error ▲ Next.js x.y.z (Turbopack)
Export encountered an error on /client/page: /client, exiting the build." - Experiments (use with caution):
`) ✓ dynamicIO
} else { ⨯ turbopackMinify (disabled by \`--debug-prerender\`)
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(` ✓ serverSourceMaps (enabled by \`--debug-prerender\`)
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client ⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
at x (<next-dist-dir>) ✓ enablePrerenderSourceMaps (enabled by \`experimental.dynamicIO\`)"
To get a more detailed stack trace and pinpoint the issue, try one of the following: `)
- Start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error. } else {
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces. expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error "⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
Export encountered an error on /client/page: /client, exiting the build." ▲ Next.js x.y.z
`) - Experiments (use with caution):
} ✓ dynamicIO
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
⨯ serverMinification (disabled by \`--debug-prerender\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ enablePrerenderSourceMaps (enabled by \`experimental.dynamicIO\`)"
`)
}
})
it('shows all prerender errors with readable stacks and code frames', async () => {
if (isTurbopack) {
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(`
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at Page (turbopack:///[project]/app/client/page.tsx:4:27)
2 |
3 | export default function Page() {
> 4 | return <p>Current time: {new Date().toISOString()}</p>
| ^
5 | }
6 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error.
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Route "/server" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at Page (turbopack:///[project]/app/server/page.tsx:13:26)
11 | await cachedDelay()
12 |
> 13 | return <p>Random: {Math.random()}</p>
| ^
14 | }
15 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/server" in your browser to investigate the error.
Error occurred prerendering page "/server". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/client/page: /client
/server/page: /server"
`)
} else {
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(`
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at Page (webpack:///app/client/page.tsx:4:27)
2 |
3 | export default function Page() {
> 4 | return <p>Current time: {new Date().toISOString()}</p>
| ^
5 | }
6 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error.
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Route "/server" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at Page (webpack:///app/server/page.tsx:13:26)
11 | await cachedDelay()
12 |
> 13 | return <p>Random: {Math.random()}</p>
| ^
14 | }
15 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/server" in your browser to investigate the error.
Error occurred prerendering page "/server". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/client/page: /client
/server/page: /server"
`)
}
})
}) })
}) })
describe('with --debug-prerender', () => { describe('without a next config file', () => {
const { next, isTurbopack } = nextTestSetup({ describe('without --debug-prerender', () => {
files: __dirname, const { next, isTurbopack } = nextTestSetup({
skipStart: true, files: path.join(__dirname, 'fixtures/without-config-file'),
buildArgs: ['--debug-prerender'], skipStart: true,
}) })
beforeAll(() => next.build()) beforeAll(() => next.build())
it('prints a warning and the customized experimental flags', async () => { it('prints no experimental flags', async () => {
if (isTurbopack) { if (isTurbopack) {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(` expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production. `"▲ Next.js x.y.z (Turbopack)"`
▲ Next.js x.y.z (Turbopack) )
- Experiments (use with caution): } else {
✓ dynamicIO expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(
⨯ turbopackMinify (disabled by \`--debug-prerender\`) `"▲ Next.js x.y.z"`
✓ serverSourceMaps (enabled by \`--debug-prerender\`) )
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`) }
✓ enablePrerenderSourceMaps (enabled by \`experimental.dynamicIO\`)" })
`)
} else {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
▲ Next.js x.y.z
- Experiments (use with caution):
✓ dynamicIO
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
⨯ serverMinification (disabled by \`--debug-prerender\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ enablePrerenderSourceMaps (enabled by \`experimental.dynamicIO\`)"
`)
}
}) })
it('shows all prerender errors with readable stacks and code frames', async () => { describe('with --debug-prerender', () => {
if (isTurbopack) { const { next, isTurbopack } = nextTestSetup({
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(` files: path.join(__dirname, 'fixtures/without-config-file'),
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client skipStart: true,
at Page (turbopack:///[project]/app/client/page.tsx:4:27) buildArgs: ['--debug-prerender'],
2 | })
3 | export default function Page() {
> 4 | return <p>Current time: {new Date().toISOString()}</p> beforeAll(() => next.build())
| ^
5 | } it('prints a warning and the customized experimental flags', async () => {
6 | if (isTurbopack) {
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error. expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error "⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
Error: Route "/server" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random ▲ Next.js x.y.z (Turbopack)
at Page (turbopack:///[project]/app/server/page.tsx:13:26) - Experiments (use with caution):
11 | await cachedDelay() ⨯ turbopackMinify (disabled by \`--debug-prerender\`)
12 | ✓ serverSourceMaps (enabled by \`--debug-prerender\`)
> 13 | return <p>Random: {Math.random()}</p> ⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
| ^ ✓ enablePrerenderSourceMaps (enabled by \`--debug-prerender\`)"
14 | } `)
15 | } else {
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/server" in your browser to investigate the error. expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
Error occurred prerendering page "/server". Read more: https://nextjs.org/docs/messages/prerender-error "⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
▲ Next.js x.y.z
> Export encountered errors on following paths: - Experiments (use with caution):
/client/page: /client ✓ serverSourceMaps (enabled by \`--debug-prerender\`)
/server/page: /server" ⨯ serverMinification (disabled by \`--debug-prerender\`)
`) ⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
} else { ✓ enablePrerenderSourceMaps (enabled by \`--debug-prerender\`)"
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(` `)
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client }
at Page (webpack:///app/client/page.tsx:4:27) })
2 |
3 | export default function Page() {
> 4 | return <p>Current time: {new Date().toISOString()}</p>
| ^
5 | }
6 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error.
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Route "/server" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at Page (webpack:///app/server/page.tsx:13:26)
11 | await cachedDelay()
12 |
> 13 | return <p>Random: {Math.random()}</p>
| ^
14 | }
15 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/server" in your browser to investigate the error.
Error occurred prerendering page "/server". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/client/page: /client
/server/page: /server"
`)
}
}) })
}) })
}) })
......
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>
}
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