Skip to content

Conversation

@Sophmrs
Copy link

@Sophmrs Sophmrs commented Jan 23, 2026

What's the purpose of this pull request?

The migration from Vercel to Homebrew of an account that uses NEXT_PUBLIC_* env vars failed as the builds in homebrew weren't inlining these env vars as expected.

How it works?

This PR adds a step during build to copy the .env from the source to the temporary .faststore directory, so that Nextjs can properly read the NEXT_PUBLIC_* env vars during build.

How to test it?

  • Add a NEXT_PUBLIC env var in the store code: console.log('NEXT_PUBLIC_TEST_VALUE', process.env.NEXT_PUBLIC_TEST_VALUE)
  • Create a .env file in the store with NEXT_PUBLIC_TEST_VALUE=test
  • Run yarn build
    • Without this change, searching the built code for the variable, you can see the value was not inlined image

    • With this change, you can see the value was inlined as expected image

Starters Deploy Preview

References

Migration preventive incident (#inc-4855): https://vtex.enterprise.slack.com/archives/C0AB4N24R7A

Summary by CodeRabbit

  • Bug Fixes
    • Fixed environment variable handling during builds: public NEXT_PUBLIC_* variables are now ensured to be present in the build temporary directory when a .env file exists, improving consistency of public env values during generate/build steps.
    • Reduces intermittent missing-public-variable issues across local and CI builds.

✏️ Tip: You can customize this high-level summary in your review settings.

@Sophmrs Sophmrs requested a review from a team as a code owner January 23, 2026 15:33
@Sophmrs Sophmrs added the bug Something isn't working label Jan 23, 2026
@Sophmrs Sophmrs requested review from eduardoformiga and renatamottam and removed request for a team January 23, 2026 15:33
@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

Adds a public copyDotenv(basePath: string, tmpPath: string) to packages/cli/src/commands/build.ts and invokes it in Build.run after generation to copy an existing .env from the project base into the temporary build directory so NEXT_PUBLIC_* variables are available during the build.

Changes

Cohort / File(s) Summary
Build Environment Variables
packages/cli/src/commands/build.ts
Added exported copyDotenv(basePath, tmpPath) that copies .env from basePath to tmpPath if present (uses existsSync/copySync). Integrated a call to copyDotenv in Build.run after generate completes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🌍 A .env file takes flight,
Copied to shadows where builds ignite,
Public secrets find their way,
Into NEXT_PUBLIC_* display,
Environment crafted, just right! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: copying the .env file to the build directory to fix missing NEXT_PUBLIC_* environment variables during builds.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 23, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@Sophmrs Sophmrs changed the base branch from dev to main January 23, 2026 17:18
@Sophmrs Sophmrs added the hotfix Address critical bugs that need to be fixed immediately label Jan 23, 2026
@Sophmrs Sophmrs force-pushed the fix/copy-env-during-build branch from 58b957f to 528d104 Compare January 23, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hotfix Address critical bugs that need to be fixed immediately

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants