How to resolve npm ERR! missing script: watch issue

The missing script: “watch” error means that npm can’t find the watch property in your package.json file.

The error usually appears when you run the npm run watch command from the command line.

The error message looks like this:

$ npm run watch
npm ERR! Missing script: "watch"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

npm ERR! A complete log of this run can be found in:
...

The npm run watch command is used to run the watch script in your package.json property.

To resolve the missing script: “watch” error, you must have a watch script available in the scripts section of your package.json file.

Here’s an example of a watch script:

{
  "name": "n-app",
  "version": "1.0.0",
  "scripts": {
    "dev": "mix",
    "watch": "mix watch",
    "production": "mix --production"
  }
}

The content of the watch script depends on the configuration of your application.

It should look similar to this:

{
  "scripts": {
    "watch": "commands go here"
  }
}

What command you write in the script is up to you.

Once you have a watch npm script added to your package.json file, the error should be resolved.

If that doesn’t work, make sure that your package.json file doesn’t contain multiple scripts object.

Consider the following example:

{
  "name": "n-app",
  "version": "1.0.0",
  "scripts": {
    "watch": "mix watch",
  },
  "scripts": {
    "dev": "mix"
  }
}

When you have two scripts as in the example above, the second scripts section will override the first one.

You can verify the available scripts by running the npm run command as shown below:

$ npm run
Scripts available in [email protected] via `npm run-script`:
  dev
    mix

To fix this, you need to merge the two scripts as one.

Move the dev script into the first scripts section as shown below:

{
  "name": "n-app",
  "version": "1.0.0",
  "scripts": {
    "watch": "mix watch",
    "dev": "mix"
  }
}

Save the changes, then run the npm run command again to verify the fix:

Scripts available in [email protected] via `npm run-script`:
  watch
    mix watch
  dev
    mix

As you can see, now both watch and dev scripts are available to run from the command line.

Now you should be able to run the npm run watch command successfully. Good work! 😉

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.