What versions & operating system are you using?
System:
OS: Windows 11 10.0.26200
CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12400F
Memory: 5.38 GB / 15.85 GB
Binaries:
Node: 24.13.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Users\wesli\AppData\Roaming\npm\yarn.CMD
npm: 10.4.0 - C:\Program Files\nodejs\npm.CMD
bun: 1.3.7 - C:\Users\wesli.bun\bin\bun.EXE
npmPackages:
@cloudflare/vite-plugin: ^1.54.3 => 1.54.3
wrangler: ^4.128.0 => 4.128.0
Please provide a link to a minimal reproduction
https://github.com/Karsten-Zhou/wrangler-migrations-bug-repro
Describe the Bug
Issue
When using @cloudflare/vite-plugin + wrangler deploy with auto-provisioning, the original wrangler.jsonc gets its migrations_dir path incorrectly rewritten.
Project Layout
project/
├── wrangler.jsonc # Original config
├── vite.config.ts # @cloudflare/vite-plugin
├── package.json
├── tsconfig.json
├── migrations/
│ └── 0001_init.sql
└── server/
└── index.ts
Steps to Reproduce
-
Install dependencies:
-
Build the project:
-
Deploy the first time (the subsequent deployments won't trigger the auto-provisioning):
What Happens
-
@cloudflare/vite-plugin generates dist/my-app/wrangler.json with:
"migrations_dir": "../../migrations"
This is correct relative to dist/my-app/.
-
Wrangler auto-provisions the D1 database (since database_id is missing).
-
Wrangler writes the database_id back to the config.
-
BUG: It also writes "migrations_dir": "../../migrations" into the original wrangler.jsonc.
-
The original config now has an incorrect path. Subsequent database migrations fail because ../../migrations is wrong relative to the project root.
Root Cause
The bug is in the interaction between two Wrangler behaviors:
- Vite plugin (
output-config.ts) correctly rewrites migrations_dir for the generated dist/<name>/wrangler.json.
- Wrangler auto-provisioning (
experimental_patchConfig) writes the entire binding object (including the rewritten migrations_dir) back to the original config file, instead of only updating the database_id or preserving the original migrations_dir value.
Expected Fix
When experimental_patchConfig patches the original wrangler.jsonc, it should either:
- Only patch the
database_id field, leaving migrations_dir untouched
- Rebase
migrations_dir back to the original config's directory before writing
Please provide any relevant error logs
No response
What versions & operating system are you using?
System:
OS: Windows 11 10.0.26200
CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12400F
Memory: 5.38 GB / 15.85 GB
Binaries:
Node: 24.13.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Users\wesli\AppData\Roaming\npm\yarn.CMD
npm: 10.4.0 - C:\Program Files\nodejs\npm.CMD
bun: 1.3.7 - C:\Users\wesli.bun\bin\bun.EXE
npmPackages:
@cloudflare/vite-plugin: ^1.54.3 => 1.54.3
wrangler: ^4.128.0 => 4.128.0
Please provide a link to a minimal reproduction
https://github.com/Karsten-Zhou/wrangler-migrations-bug-repro
Describe the Bug
Issue
When using
@cloudflare/vite-plugin+wrangler deploywith auto-provisioning, the originalwrangler.jsoncgets itsmigrations_dirpath incorrectly rewritten.Project Layout
Steps to Reproduce
Install dependencies:
Build the project:
Deploy the first time (the subsequent deployments won't trigger the auto-provisioning):
What Happens
@cloudflare/vite-plugingeneratesdist/my-app/wrangler.jsonwith:This is correct relative to
dist/my-app/.Wrangler auto-provisions the D1 database (since
database_idis missing).Wrangler writes the
database_idback to the config.BUG: It also writes
"migrations_dir": "../../migrations"into the originalwrangler.jsonc.The original config now has an incorrect path. Subsequent database migrations fail because
../../migrationsis wrong relative to the project root.Root Cause
The bug is in the interaction between two Wrangler behaviors:
output-config.ts) correctly rewritesmigrations_dirfor the generateddist/<name>/wrangler.json.experimental_patchConfig) writes the entire binding object (including the rewrittenmigrations_dir) back to the original config file, instead of only updating thedatabase_idor preserving the originalmigrations_dirvalue.Expected Fix
When
experimental_patchConfigpatches the originalwrangler.jsonc, it should either:database_idfield, leavingmigrations_diruntouchedmigrations_dirback to the original config's directory before writingPlease provide any relevant error logs
No response