-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
NX_ environment variables are undefined on a client in Next.js development #17940
Comments
i am suffering this too. |
when is it solved? i need to upgrade to next.js 13.4 :) |
Same here with Next 13.4.19 and NX 16.7.3. Env variables are not working anymore.. |
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
This probably started occurring when we switched over to use the Next CLI. Moving forward, we want to keep our package close to Next.js' as such we will deprecate this feature and it will be removed in Nx 18. |
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
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
Environment variables that are prefixed with
NX_
are undefined during development in Next.js on a client. They work as expected on the server's side. It works correctly in production mode though. Both a client and server show correct environment variables.Expected Behavior
Environment variables that are prefixed with
NX_
should be defined on a client during development.GitHub Repo
https://github.com/skoob13/nx-next-dev-server-bug
Steps to Reproduce
yarn nx run ui:serve
localhost:4200
in a browserNx Report
Failure Logs
No response
Operating System
Additional Information
I've tested different Next.js versions and environment variables don't work on a client on any 13.4.* version. It works correctly on 13.3.* versions though.
As a temporary solution it's possible to use
env
in next.config.js defining prefixed withNX_
variables manually.The text was updated successfully, but these errors were encountered: