Error: could not find worker script" on wrangler deploy
Diagnoses the wrangler deploy failure 'could not find worker script'. Use it when a deploy cannot locate the entry file, typically after a rename, a wrong working directory, or a monorepo deploy run from the repo root. The key trigger is the exact 'could not find worker script' message.
TL;DR
Wrangler cannot find your entry file, so the deploy stops before it uploads anything. Nine times out of ten the main path in wrangler.toml points at a file that moved or was renamed, or you ran deploy from the wrong directory. Check that the file exists relative to the config, fix the path or cd into the worker package, then redeploy.
Error: could not find worker scriptSteps
- Confirm you are in the worker's directory and the config is here:
pwd
ls wrangler.toml wrangler.jsoncExpected: pwd shows the worker package directory, and one of the two config files is listed.
- Read the
mainvalue from the config, then check that exact file exists:
grep -n '^main' wrangler.toml
test -f src/index.ts && echo entry foundExpected: the grep shows a path like main = "src/index.ts", and the test prints "entry found". If it does not, the path is wrong or the file moved.
- Fix the mismatch. Either update
mainto the real relative path, or run the deploy from the directory that holds the config. In a monorepo, pass the config explicitly:
wrangler deploy --config packages/api/wrangler.tomlExpected: wrangler finds the entry and starts bundling instead of erroring.
- Run the full deploy and watch for the upload summary:
wrangler deployExpected: a "Total Upload" line and a deployed workers.dev URL, no script error.
Use this when
wrangler deployfails with "could not find worker script"- The error appeared right after renaming or moving the entry file
- Deploying a monorepo package from the repo root
- The config references an entry path that does not exist on disk
Not for this skill when
- The deploy fails on script size (see the script-too-large skill)
- The entry file exists but the deploy fails on bindings or config validation
- The error is at runtime in the browser, not at deploy time
- You are deploying Pages, not a Worker
Variant phrasings
- wrangler deploy could not find worker script
- "could not find worker script" wrangler
- wrangler error finding worker entry point on deploy
Why it happens
Wrangler resolves the main entry path relative to the config file, not relative to your shell's working directory. The default scaffold expects src/index.ts (older templates used src/index.js), so any rename, move, or deploy run from a parent directory breaks the lookup. Monorepo CI jobs that run from the repo root hit this constantly.
Edge cases
- If both wrangler.toml and wrangler.jsonc exist, wrangler prefers one of them; make sure you are editing the file it actually reads.
- A
mainpath that exists but points at a directory instead of a file fails the same way. - Case-sensitive filesystems:
Src/index.tsis notsrc/index.tson Linux CI even if it works on macOS. - After fixing, a stale wrangler dev process may still serve the old bundle; restart it.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_GHaDGsZdiBGvp16OMpUJFA