/errors/yarn/command-not-found
yarn: error Command "dev" not found.
- tool
- Yarn
- exit code
- 1
- versions
- Yarn 1.22, Yarn 4.x
- os
- any
error Command "dev" not found. is Yarn 1 (Classic) saying that yarn dev or yarn run dev matched neither a script in package.json nor an executable in node_modules/.bin. Run yarn run with no arguments to see what exists, then add the missing script or use the right name. Yarn 2 and later report the same problem as Usage Error: Couldn't find a script named "dev".
Reproduce it (Yarn 1)
cat > package.json <<'EOF'
{ "name": "app", "version": "1.0.0", "license": "MIT", "scripts": { "build": "echo build" } }
EOF
npx --yes yarn@1 devOutput · exit 1
yarn run v1.22.22 error Command "dev" not found. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The same mistake in Yarn 4
cat > package.json <<'EOF'
{ "name": "app", "version": "1.0.0", "license": "MIT", "scripts": { "build": "echo build" } }
EOF
touch yarn.lock
npx --yes @yarnpkg/cli-dist@4 install > /dev/null 2>&1
npx --yes @yarnpkg/cli-dist@4 run devOutput · exit 1
Usage Error: Couldn't find a script named "dev". $ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] [--require #0] <scriptName> ...
An empty yarn.lock marks the folder as a Yarn project root, and Yarn 4 needs an install before it runs scripts.
Fix
Add the script, or call the name that exists:
cat > package.json <<'EOF'
{ "name": "app", "version": "1.0.0", "license": "MIT",
"scripts": { "build": "echo build", "dev": "echo dev server" } }
EOF
npx --yes yarn@1 --silent devOutput
dev server
What yarn NAME looks up
| Order | Yarn 1 | Yarn 2+ |
|---|---|---|
| 1 | Script in package.json "scripts" | Script in package.json "scripts" |
| 2 | Binary in node_modules/.bin | Binary of a declared dependency |
| 3 | error Command "NAME" not found. | Usage Error: Couldn't find a script named "NAME". |
A Yarn built-in command with the same name (yarn install, yarn add, yarn test in older versions) is not looked up as a script. Use yarn run NAME to force the script.