Allow dotenv files from different environments for SSR and SSG in Next.js#7323
Merged
chalosalvador merged 14 commits intomasterfrom Aug 14, 2024
Merged
Allow dotenv files from different environments for SSR and SSG in Next.js#7323chalosalvador merged 14 commits intomasterfrom
chalosalvador merged 14 commits intomasterfrom
Conversation
…the build process
jamesdaniels
requested changes
Jul 8, 2024
Member
jamesdaniels
left a comment
There was a problem hiding this comment.
Can we add some test coverage?
…osalvador/dotenv-files
…base-tools into chalosalvador/dotenv-files
src/frameworks/next/index.ts
Outdated
| const projectEnvVars = parseStrict((await readFile(projectEnvPath)).toString()); | ||
|
|
||
| // Merge the parsed variables with the existing environment variables | ||
| Object.assign(env, projectEnvVars); |
Member
There was a problem hiding this comment.
dotenv does not override environment variables by default if i recall, so this logic will likely need inverting { ...projectEnvVars, ...process.env }
Member
Author
There was a problem hiding this comment.
@jamesdaniels I just made this change, added tests for the parseStrict function and added the changelog.
jamesdaniels
requested changes
Jul 10, 2024
Member
jamesdaniels
left a comment
There was a problem hiding this comment.
See small comment on overrides, add tests, and changelog—otherwise LGTM
…base-tools into chalosalvador/dotenv-files
jamesdaniels
approved these changes
Aug 7, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is intended to fix the issue #7207 by checking if the .env. file exists and make it available for the build process.
Scenarios Tested
.env.<PROJECT-ID>file in the root of the Next.js project.env.<PROJECT-ID>.env.<PROJECT-ID>.env.<PROJECT-ID>is available in a server side rendered page..env.<PROJECT-ID>is available in a static generated page.Sample Commands