npm start says the script is missing
npm ERR! Missing script: "start"Short answer
npm start runs the start script from the nearest package.json. The error means that file has no start entry and no server.js in its root for npm to fall back on. Add the script, run the one the project really uses (npm run lists them), or move to the right folder or workspace.
Fix it fast
1Find out which cause you have
Print which package.json npm is using and the scripts it lists. If the folder is not the one you expected, that is the cause; if it is, the list shows what the project calls its start command.
npm prefix npm run2Match what you see, then jump to its fix
- 1
npm run lists no start entry, and the project root has no file named server.jspackage.json has no start script and there is no server.jsFix - 2
npm run shows scripts like dev, serve or watch but no startThe project uses a different script name such as dev or serveFix - 3
npm prefix prints a folder that is not your app, such as a parent folder or a monorepo rootnpm picked up a different package.json than the one you meantFix - 4
The root package.json has a workspaces field and the start script is in packages/<name>/package.jsonThe script lives in a workspace, not in the root packageFix
- 1
What does the error look like?
npm ERR! Missing script: "start"npm error Missing script: "start"npm error To see a list of scripts, run:
Cause 1 of 4
package.json has no start script and there is no server.js
1Check
npm only invents a start command in one case: when a file called server.js sits in the package root, start defaults to node server.js. Without that file the script must be written down.
ls server.js
npm run2Fix
Add a start script that runs your real entry file. If your entry is already server.js you can also just leave it out.
{
"scripts": {
"start": "node index.js"
}
}3Verify
Run it; the app should boot instead of printing the error.
npm startConfirmed by docs.npmjs.com
Cause 2 of 4
The project uses a different script name such as dev or serve
1Check
With no argument, npm run prints every script the package defines. Frameworks often name the development command dev, and the production command only exists after a build.
npm run2Fix
Run the script that exists. If you want npm start to work too (many hosts call it), point start at the same command.
npm run dev
# package.json, if hosting expects npm start
"scripts": { "start": "vite preview" }3Verify
npm start now runs the chosen command.
npm startConfirmed by docs.npmjs.com
Cause 3 of 4
npm picked up a different package.json than the one you meant
1Check
npm prefix prints the closest parent directory containing a package.json or node_modules. Inside a subfolder with no package.json of its own, npm uses the parent's, and that one may have no start script.
pwd
npm prefix2Fix
Change into the folder whose package.json holds the script, then run it there.
cd path/to/the/app
npm start3Verify
npm prefix now prints the app folder, and npm start runs.
npm prefixConfirmed by docs.npmjs.com
Cause 4 of 4
The script lives in a workspace, not in the root package
1Check
In a workspaces monorepo the root usually has no start script of its own. Ask npm to run the script inside a named workspace instead.
grep -n workspaces package.json2Fix
Target the workspace by name, or run the script in every workspace and skip the ones without it.
npm run start --workspace=api
# every workspace that has a start script
npm run start --workspaces --if-present3Verify
The named workspace starts.
npm run start --workspace=apiConfirmed by docs.npmjs.com
How do I stop it coming back?
- Keep a start script in every deployable package.json; hosts and containers call npm start by convention.
- Run npm commands from the package folder, and check npm prefix when a command behaves oddly in a monorepo.
- In CI, use npm run <name> --if-present for optional steps so a missing script does not fail the build by accident.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
npm reports ELIFECYCLE, but the real error is somewhere else
npm ERR! errno 1
ELIFECYCLE is not the bug.
3 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
corepack enable fails: permission denied while creating the pnpm link
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm'
corepack enable writes small link files for yarn and pnpm next to your node binary.
2 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fixBack end
firebase deploy stops because the predeploy lint step failed
Error: There was an error deploying functions
The predeploy hook in firebase.json runs npm run lint before every deploy, and a failing hook cancels the deploy.
3 causes, each with a fix