Node Deployments and ‘npm ERR! Missing script’
This post will cover application failures with Node on App Service Linux - specifically regarding the npm ERR! Missing script:
message.
Prerequisites
IMPORTANT: Make sure App Service Logs are enabled first
- LogStream
- Retrieving logs directly from the Kudu site, or directly view/download via an FTP client
- Diagnose and Solve Problems -> Application Logs detector, Container Crash detector, or Container Issues detector
If App Service Logs are not enabled, only docker.log
files will be generated, which will not show application related stdout
/ stderr
and will make troubleshooting these kinds of issues more complicated.
Overview
This will be a brief post covering the message npm ERR! Missing script:
. This is targeted towards Node.js Blessed Images on App Service Linux.
Generally, this may show if a Startup command is specified, while there is no matching scripts
property in your package.json
- or, if the scripts
property or the associated command in scripts
is missing.
Consider reviewing the run logic that is defined for Node.js applications here
- Run npm start if a start script is specified.
- Else, if a script is specified in package.json’s main field, run that.
- Run the first found of the following scripts in the root of the repo:
- bin/www
- server.js
- app.js
- index.js
- hostingstart.js
With the above logic in mind, take the below package.json
:
{
"name": "azure-webapps-linux-node-express-basic",
"version": "1.0.0",
"main": "server.js",
"license": "MIT",
"dependencies": {
"axios": "^0.27.2",
"express": "^4.18.2"
},
"scripts": {
"dev": "node server.js"
}
}
The above package.json
is actually valiate to run, even without a start
property - since a scripts
property does exist. Even if it didn’t, it would then try to run node server.js
as it would eventually find server.js
(in this example)
Cause
What is not valid is having a scripts
property (or no scripts
property) but setting a Startup Command to a non-existent scripts
property.
For instance, using the above package.json
, and using the below Startup command:
Will cause the error in this post:
npm ERR! Missing script: "start:dev"
npm ERR! To see a list of scripts, run:
npm ERR! npm run
Resolution
In this case, it’s important to:
- Review your
package.json
- especially what has been deployed to Azure, as well as your local file. - Correct any missing
scripts
commands. If specifying a Startup Command in the portal, ensure this is targeting an existing command underscripts
inpackage.json
. - Validate this works locally.