nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.53k stars 2.35k forks source link

Nx uses env variable specified in .env.local instead of using given value when building in pipeline #28569

Open jvskriubakken opened 4 days ago

jvskriubakken commented 4 days ago

Current Behavior

Hi

I have several react apps and corresponding dotnet webapps. They are setup in the same way. I'm passing environment variable NX_PUBLIC_BUILD_NUMBER into every app in the Azure pipeline build like this (excerpt from yaml file):

      - script: yarn nx affected --base=$(BASE_SHA) --target=build --configuration=production --parallel=3
        displayName: "Build apps"
        env:
          NX_PUBLIC_BUILD_NUMBER: $(Build.BuildNumber)

Every react app project has file .env.local on root that contains:

NX_PUBLIC_BUILD_NUMBER=local-debug

When running the applications locally every app get the value "local-debug" from the following execution:

process.env["NX_PUBLIC_BUILD_NUMBER"]

When running the applications on the their servers, every app gets the actual build number as the value (instead of "local-debug"). However, one application still has the value "local-debug" when running on it' server. When I search for "NX_PUBLIC_BUILD_NUMBER" in the generated js-file I find "local-debug".

How can this happen? Anyone experienced this? I have compared project.json and tsconfig.json and other files between the apps working as expected and the one that doesn't, without finding any differences (other than that they reside in different paths - as expected). Hoping for some guidance on what could be causing it. Thanks!

Expected Behavior

That nx passes given environment variable to every affected react app equally.

GitHub Repo

No response

Steps to Reproduce

N/A.

Nx Report

Node : 18.20.2 OS : darwin-arm64 Native Target : aarch64-macos yarn : 1.22.19

nx (global) : 19.8.6 nx : 19.8.6 @nx/js : 19.8.6 @nx/jest : 19.8.6 @nx/linter : 19.8.6 @nx/eslint : 19.8.6 @nx/workspace : 19.8.6 @nx/cypress : 19.8.6 @nx/devkit : 19.8.6 @nx/eslint-plugin : 19.8.6 @nx/plugin : 19.8.6 @nx/react : 19.8.6 @nx/storybook : 19.8.6 @nrwl/tao : 19.8.6 @nx/vite : 19.8.6 @nx/web : 19.8.6 @nx/webpack : 19.8.6 typescript : 5.5.4

Registered Plugins: @nx/webpack/plugin @nx/eslint/plugin @nx/cypress/plugin @nx/jest/plugin @nx-dotnet/core @nx/storybook/plugin

Community plugins: @nx-dotnet/core : 2.4.5

Local workspace plugins: @airmont/nx-plugins

Failure Logs

No response

Package Manager Version

yarn 1.22.19

Operating System

Additional Information

No response

sacru2red commented 2 days ago

Is this related to this issue? #28576