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
Environment variable APP_DEPLOYMENT_ENV is undefined when running the production build (npm run build && npm start), but works fine in development mode (npm run dev).
Steps to Reproduce
.env file exists with APP_DEPLOYMENT_ENV="production"
Hi @foxlau thanks for creating the issue.
The build does not include the env vars which are set during the build process (running pnpm run build). When you run your application with pnpm run start it tries to read those environment variables from process.env, if they are not set, it fails with the above error.
During development (pnpm run dev), you dont see this error cause the react-router dev server is automatically trying to load an .env file to load them as environment variables. In production though, they should be set as actual environment variables.
If you want to test that out locally you can try to do:
pnpm run build
APP_DEPLOYMENT_ENV=production pnpm run start
or if you have dotenvx installed globally, you can run this to let dotenvx try to load env vars from an .env file like so:
pnpm run build
dotenvx run -- pnpm run start
On a production server/deployment you should set the environment variables according to the documentation of your chosen deployment platform.
Description
Environment variable
APP_DEPLOYMENT_ENV
is undefined when running the production build (npm run build && npm start
), but works fine in development mode (npm run dev
).Steps to Reproduce
.env
file exists withAPP_DEPLOYMENT_ENV="production"
npm run dev
- works finenpm run build && npm start
- fails with:Environment
npm run dev
)Could this be related to how environment variables are handled during the production build process?
The text was updated successfully, but these errors were encountered: