Description
I'm using React Router as a...
framework
Reproduction
- Create a new project with React Router Cloudflare D1 template
- Create a
.dev.vars
file in the root of the project - Build the project
npx create-react-router@latest --template remix-run/react-router-templates/cloudflare-d1
cd my-react-router-app
npm i
echo "SECRET=default" > .dev.vars
npm run build
The build folder now contains a file ./server/.dev.vars
:
Multi environments
The same problem occurs when you are working with different Cloudflare environments configured in wrangler.jsonc
, but then the behaviour differs slightly.
ℹ️ How to reproduce with multiple environments?
- Create a new project with React Router Cloudflare D1 template
- Create a
.dev.vars
file in the root of the project to store development variables/secrets. - Create a
.dev.vars.staging
file to store staging variables/secrets. - Create a file named
.env.staging
with contentCLOUDFLARE_ENV=staging
to instruct Vite to use the right Cloudflare environment. - Build the project with Vite in mode 'staging'
npx create-react-router@latest --template remix-run/react-router-templates/cloudflare-d1
cd my-react-router-app
npm i
echo "SECRET=default" > .dev.vars
echo "SECRET=staging" > .dev.vars.staging
echo "CLOUDFLARE_ENV=staging" > .env.staging
npm run build -- --mode=staging
Again, the build folder now contains a file named ./server/.dev.vars
(same as before), but now with the staging secrets:
System Info
System:
OS: macOS 15.5
CPU: (10) arm64 Apple M1 Pro
Memory: 209.05 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
Browsers:
Chrome: 136.0.7103.114
Safari: 18.5
npmPackages:
@react-router/dev: ^7.5.3 => 7.6.0
react-router: ^7.5.3 => 7.6.0
vite: ^6.3.3 => 6.3.5
Used Package Manager
npm
Expected Behavior
I'm not expecting the contents of .dev.vars
and .dev.vars.{environment}
to be included in server bundle, because it's meant to store secrets, see Cloudflare Documentation. This behaviour has changed compared to remix where the file did not end up in the build output.
Actual Behavior
Cloudflare Worker Secrets defined in .dev.vars
or .dev.vars.{environment}
are being bundled to ./build/server/.dev.vars