## 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.

```text
Error: could not find worker script
```

## Steps

1. Confirm you are in the worker's directory and the config is here:
```sh
pwd
ls wrangler.toml wrangler.jsonc
```
Expected: `pwd` shows the worker package directory, and one of the two config files is listed.

2. Read the `main` value from the config, then check that exact file exists:
```sh
grep -n '^main' wrangler.toml
test -f src/index.ts && echo entry found
```
Expected: 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.

3. Fix the mismatch. Either update `main` to the real relative path, or run the deploy from the directory that holds the config. In a monorepo, pass the config explicitly:
```sh
wrangler deploy --config packages/api/wrangler.toml
```
Expected: wrangler finds the entry and starts bundling instead of erroring.

4. Run the full deploy and watch for the upload summary:
```sh
wrangler deploy
```
Expected: a "Total Upload" line and a deployed workers.dev URL, no script error.

## Use this when
- `wrangler deploy` fails 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 `main` path that exists but points at a directory instead of a file fails the same way.
- Case-sensitive filesystems: `Src/index.ts` is not `src/index.ts` on 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
