Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dotenv files from different environments for SSR and SSG in Next.js #7323

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

chalosalvador
Copy link
Member

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

  1. Initialized a hosting project with Next.js
  2. Created a .env.<PROJECT-ID> file in the root of the Next.js project
  3. Created a page that uses SSR and accesses the environment variable in .env.<PROJECT-ID>
  4. Created a page that uses SSG and accesses the environment variable in .env.<PROJECT-ID>
  5. Deployed the project to Firebase hosting.
  6. Make sure the environment variable in the .env.<PROJECT-ID> is available in a server side rendered page.
  7. Make sure the environment variable in the .env.<PROJECT-ID> is available in a static generated page.

Sample Commands

Copy link
Member

@jamesdaniels jamesdaniels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some test coverage?

src/frameworks/next/index.ts Outdated Show resolved Hide resolved
const projectEnvVars = parseStrict((await readFile(projectEnvPath)).toString());

// Merge the parsed variables with the existing environment variables
Object.assign(env, projectEnvVars);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotenv does not override environment variables by default if i recall, so this logic will likely need inverting { ...projectEnvVars, ...process.env }

Copy link
Member

@jamesdaniels jamesdaniels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See small comment on overrides, add tests, and changelog—otherwise LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants