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

fix(nextjs): Deprecate adding NX_ vars to Webpack Define #18892

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

ndcunningham
Copy link
Contributor

When we added NX_ vars to Webpack Define it would be available to both the client and server. This does not follow Next.js' concept to only add environment variables prefixed with NEXT_PUBLIC_ to the client.

Now if a NX_ var was found and it is not a Nx defined variable the console will warn with:

Warning, in NX 18 environment variables starting with NX_ will not be available in the browser, and currently will not work with @nx/next:server executor.
Please rename the following environment variables: NX_VAR_FOUND using Next.js' built-in support for environment variables. Reference https://nextjs.org/docs/pages/api-reference/next-config-js/env

After Nx 18, to get access to environment variables declared in the .env file consumers should use the NEXT_ or NEXT_PUBLIC_ prefix.

closes: #17940

@ndcunningham ndcunningham requested a review from a team as a code owner August 29, 2023 18:29
@ndcunningham ndcunningham self-assigned this Aug 29, 2023
@vercel
Copy link

vercel bot commented Aug 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Aug 29, 2023 8:11pm

Copy link
Member

@jaysoo jaysoo left a comment

Choose a reason for hiding this comment

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

One comment, otherwise LGTM

When we add NX_ vars to Webpack Define it would be available to both client and server.
This does not follow Next.js' concept to only add environment variables prefixed with NEXT_PUBLIC_ to the client

As such to get acces to environment variables declared in the .env file consumers should use the NEXT_ or NEXT_PUBLIC_ prefix

closes: nrwl#17940
@ndcunningham ndcunningham enabled auto-merge (squash) August 29, 2023 19:25
@ndcunningham ndcunningham merged commit da2a08e into nrwl:master Aug 29, 2023
2 checks passed
@ndcunningham ndcunningham deleted the chore/add-warning-next-env branch August 30, 2023 15:14
@github-actions
Copy link

github-actions bot commented Sep 5, 2023

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NX_ environment variables are undefined on a client in Next.js development
2 participants