[BUG] Prevent External Libraries from Overwriting Environment Variables Configuration in NX Build
Dariuszsibik opened this issue · 0 comments
Current Behavior
After adding the Storybook packages, the environment variables configured in NX are either overwritten or become undefined after the build and serve:[prefix for env file] (example:
.env.serve[prefix]). This issue occurs even without any additional code implementation; simply adding the Storybook library to the package.json will cause it to be installed during the build.
Expected Behavior
NX should preserve the environment variables configuration, and external libraries should not override or affect the environment variables during the build process.
GitHub Repo
No response
Steps to Reproduce
- Set up a project using NX 19 and Next.js 14.
- Configure environment variables using the recommended approach for runtime (with the serve prefix, e.g.,
.env.serve.local
). - Add external libraries or packages like Storybook (@storybook/nextjs, @storybook/react-webpack5, @storybook/server-webpack5) to package.json.
- Build the project using NX.
- Run application using
serve:[appropriate prefix for the environment variable file]
- Observe that environment variables are overwritten or undefined after the build.
Nx Report
Node : 23.4.0
OS : darwin-arm64
Native Target : aarch64-macos
yarn : 1.22.22
nx (global) : 20.2.2
nx : 19.8.10
@nx/js : 19.8.10
@nx/jest : 19.8.10
@nx/linter : 19.8.10
@nx/eslint : 19.8.10
@nx/workspace : 19.8.10
@nx/cypress : 19.8.10
@nx/devkit : 19.8.10
@nx/eslint-plugin : 19.8.10
@nx/next : 19.8.10
@nx/playwright : 19.8.10
@nx/plugin : 19.8.10
@nx/react : 19.8.10
@nx/storybook : 19.8.10
@nrwl/tao : 19.8.10
@nx/vite : 19.8.10
@nx/web : 19.8.10
@nx/webpack : 19.8.10
typescript : 4.9.5
Failure Logs
Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
How can I prevent external libraries (like Storybook) from overwriting or affecting environment variable configurations in NX during the build and serve:[prefix] with specific environment file?
Is there a way to exclude specific libraries from altering environment variables in the build process?