Closed
Description
I'm using React Router as a...
framework
Reproduction
https://stackblitz.com/edit/github-qphddjff?file=app%2Froutes%2Fhome.tsx
- Open the repro
- Clear the terminal and build it locally with
npm run build
- Start the preview server with
npm run start
- See that it logs
undefined
in the loader, although I even installeddotenv-cli
which according to this discussion should fix it - When uncommenting the
define
invite-config.ts
it works, however I get a warning while building, that this could be a security flaw
System Info
System:
OS: macOS 15.5
CPU: (10) arm64 Apple M1 Max
Memory: 222.20 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.13.0 - ~/.nvm/versions/node/v22.13.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.13.0/bin/yarn
npm: 10.9.2 - ~/.nvm/versions/node/v22.13.0/bin/npm
pnpm: 10.12.1 - ~/.nvm/versions/node/v22.13.0/bin/pnpm
bun: 1.1.45 - ~/.nvm/versions/node/v22.13.0/bin/bun
Browsers:
Chrome: 137.0.7151.105
Safari: 18.5
npmPackages:
@react-router/dev: ^7.5.3 => 7.6.2
@react-router/node: ^7.5.3 => 7.6.2
@react-router/serve: ^7.5.3 => 7.6.2
react-router: ^7.5.3 => 7.6.2
vite: ^6.3.3 => 6.3.5
Used Package Manager
npm
Expected Behavior
When starting the production build locally, all environment variables from .env should be available in server-side loader functions.
Actual Behavior
I’m running into the same issue as described in this discussion, but even with dotenv-cli installed and the recommended setup, environment variables are not available during a local production build.