npm Missing Script Error

Recently I’ve been using Netlify Dev to add some serverless functions to an existing Netlify hosted site. Netlify Dev picks up that we use Gatsby as our static site generator automatically.

When trying to run netlify dev, I received this error:

ERR! missing script: gatsby

The Netlify cli is looking for a script named ‘gatsby’. Gatsby is installed as a project dependency but Netlify cli is trying to run it as an npm run ccommand and it cannot find the script as it is not a script in package.json.

How To Fix This Type of Error

If you get an error like this:

ERR! missing script: <name>
  1. Check that the package is a dependency (in package.json)
  2. Check node_modules/.bin/<name> to ensure that the file has been symlinked
  3. Check the symlinked file exists
  4. Check that the script exists. If not, add a new script with that name in the project’s package.json
// package.json
  "scripts": {
    "gatsby": "gatsby",