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

.env.local environment variables are not being picked up after upgrading from NX v18 to v19 #23362

Open
2 of 4 tasks
barrymichaeldoyle opened this issue May 14, 2024 · 4 comments
Assignees
Labels
community This is a good first issue for contributing scope: bundlers Issues related to webpack, rollup type: bug

Comments

@barrymichaeldoyle
Copy link
Contributor

Current Behavior

Before I updated my project from NX v18 to v19, my environment variables e.g. NX_USE_MSW in .env.local would work perfectly fine. I could log it out. Now that I've updated to v19, it logs out as undefined instead of the value I set it to.

When I move back to my branch with v18, everything works fine again.

Expected Behavior

I expect my environment variables to work when updating, or I expect a docs update on the migration required here.

GitHub Repo

No response

Steps to Reproduce

  1. Create a .env.local file at the root of the NX Project
  2. Add a value there like NX_SOME_KEY=SOME_VALUE
  3. Add a console log to process.env["NX_SOME_KEY"]
  4. Serve your app
  5. It will log undefined, instead of the expected "SOME_VALUE"

Nx Report

Node   : 20.12.0
OS     : linux-arm64
npm    : 10.5.0

nx                 : 19.0.3
@nx/js             : 19.0.3
@nx/jest           : 19.0.3
@nx/linter         : 19.0.3
@nx/eslint         : 19.0.3
@nx/workspace      : 19.0.3
@nx/cypress        : 19.0.3
@nx/devkit         : 19.0.3
@nx/eslint-plugin  : 19.0.3
@nx/playwright     : 19.0.3
@nx/react          : 19.0.3
@nx/storybook      : 19.0.3
@nrwl/tao          : 19.0.3
@nx/web            : 19.0.3
@nx/webpack        : 19.0.3
typescript         : 5.4.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

I'm using module federation and running the project in a dev-container if that might have anything to do with it.

@barrymichaeldoyle
Copy link
Contributor Author

It is probably also worth noting that the upgrade from NX v18 to v19 meant that my React version updated to 18.3.

@barrymichaeldoyle
Copy link
Contributor Author

Ah I just found this:

https://nx.dev/blog/2024-05-08-nx-19-release#breaking-change-updating-bundled-environment-variables-to

I'll go make a PR to update the docs...

@FrozenPandaz FrozenPandaz added the scope: bundlers Issues related to webpack, rollup label May 14, 2024
@FrozenPandaz
Copy link
Collaborator

This this is an intentional breaking change for security reasons. Environment variables must now be prefixed with NX_PUBLIC_.

It is also mentioned here:
https://nx.dev/changelog#nx-19

Where are the docs that you found which are not updated?

@barrymichaeldoyle
Copy link
Contributor Author

This this is an intentional breaking change for security reasons. Environment variables must now be prefixed with NX_PUBLIC_.

It is also mentioned here: https://nx.dev/changelog#nx-19

Where are the docs that you found which are not updated?

It was in the define-environment-variables.md file. It might be in others as well though. Create a PR #23397 for this though :)

leosvelperez pushed a commit that referenced this issue May 15, 2024
#23397)

## Current Behavior
Incorrect environment variable prefix `NX_` in docs.

## Expected Behavior
Correct environment variable prefix `NX_PUBLIC_` in docs.

## Related Issue(s)
#23362
FrozenPandaz pushed a commit that referenced this issue May 15, 2024
#23397)

## Current Behavior
Incorrect environment variable prefix `NX_` in docs.

## Expected Behavior
Correct environment variable prefix `NX_PUBLIC_` in docs.

## Related Issue(s)
#23362
(cherry picked from commit 38a947f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community This is a good first issue for contributing scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

No branches or pull requests

3 participants