Skip to content

Conversation

@laishere
Copy link

Fix #80194.
This adds the missing env inlining and hash replacing for standalone mode bundled by webpack. This issue does not occur in turbopack mode because generate-env is not involved.
To reproduce, please clone https://github.com/hood/nextjs-env-repro. And change the build script to:

  "scripts": {
    "build": "cp .env.local .env.production && rm -rf ./.next/ && next build --webpack --experimental-build-mode compile && next build --webpack --experimental-build-mode generate-env && cp -r ./.next/static ./.next/standalone/.next/static"
  },

This repository uses next@15.3.3, I added --webpack to ensure it works as expected in the latest next@16.0.0 since the default bundler is changed to Turbopack now.
Then run:

pnpm build && node .next/standalone/server.js

The expected result is the NEXT_PUBLIC_ environment varaible is defined for client component.
The actual result is it's undefined, because the referenced js file path (hash) in standalone directory is not correct anymore after generate-env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: Since 15.3 environment variables are not available in client components using standalone output mode

2 participants