Unverified Commit 900a807d authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix legacy env case with experimental tracing (#70411)

This ensures `env` keys in `next.config` are properly exposed during
page collecting step during build since the inlining step comes after.

x-ref: https://github.com/vercel/next.js/pull/70380
x-ref:
https://vercel.com/vercel/vercel-site/9WqUX9vu15oVEy1acDqoXddcH27K?filter=errors
parent 538b1c65
......@@ -772,6 +772,15 @@ export default async function build(
await fs.mkdir(shuttleDir, {
recursive: true,
})
// since inlining comes after static generation we need
// to ensure this value is assigned to process env so it
// can still be accessed
for (const key in config.env) {
if (!process.env[key]) {
process.env[key] = config.env[key]
}
}
}
const customRoutes: CustomRoutes = await nextBuildSpan
......
export default function Page() {
if (!process.env.LEGACY_ENV_KEY) {
throw new Error('missing env key LEGACY_ENV_KEY!!')
}
return <p id="legacy-env">{process.env.LEGACY_ENV_KEY}</p>
}
......@@ -10,6 +10,9 @@ export default function Page(props) {
}
export function getStaticProps() {
if (!process.env.LEGACY_ENV_KEY) {
throw new Error('missing env key LEGACY_ENV_KEY!!')
}
return {
props: {},
}
......
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