You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created the vite project with npx create-nx-workspace@latest with the react and vite option.
.env file: VITE_BASE_PATH="7166development"
.env.production file: VITE_BASE_PATH="dogfood"
The documentation mentions: You can then use these variables in your application code like so: import.meta.env.VITE_CUSTOM_VAR.
I am using const basePath = import.meta.env.VITE_BASE_PATH; console.log('!!!!!!'); console.log(basePath);.
The compiled code though never uses the production env, but always the regular .env file - it didn't use the configuration in the project.json either.
What am I doing wrong / what's the issue?
Node version: v19.7.0
nx.json (unchanged, as created by create-nx-workspace command):
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I can't figure out how to make .env files or alternatively configuration defined in project.json to work together with react and vite.
I checked the documentation (https://nx.dev/recipes/react/use-environment-variables-in-react#environment-variable-conflict-between-nx-and-vite) and the github issue #14528 .
I tried out those variations of the commands I found on the internet and the documentation.
I tried out using the nx project root as CWD and the test-app directory as CWD - did not change the result.
The project.json that I used when trying to use the project.json for the configuration as recommended in the documentation page:
I created the vite project with
npx create-nx-workspace@latest
with the react and vite option..env file:
VITE_BASE_PATH="7166development"
.env.production file:
VITE_BASE_PATH="dogfood"
The documentation mentions:
You can then use these variables in your application code like so: import.meta.env.VITE_CUSTOM_VAR.
I am using
const basePath = import.meta.env.VITE_BASE_PATH; console.log('!!!!!!'); console.log(basePath);
.The compiled code though never uses the production env, but always the regular .env file - it didn't use the configuration in the project.json either.
What am I doing wrong / what's the issue?
Node version: v19.7.0
nx.json (unchanged, as created by create-nx-workspace command):
Beta Was this translation helpful? Give feedback.
All reactions