npm ERR! Missing script: "start", "dev", "build", "test"

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
11 min

banner

# Table of Contents

  1. npm ERR! Missing script: "start"
  2. npm ERR! Missing script: "dev"
  3. npm ERR! Missing script: "build"
  4. npm ERR! Missing script: "test"
  5. npm ERR! Missing script: "lint"
  6. npm ERR! Missing script: "watch"

Make sure to click on the relevant to you subheading in the Table of Contents.

# npm ERR! Missing script: "start"

The npm ERR! Missing script: "start" error occurs for multiple reasons:

  1. Missing a start script in the scripts section of your package.json file.
  2. Opening your IDE or shell in a directory that doesn't contain your package.json file.
  3. Not having initialized a package.json file for your project.
  4. Using an outdated version of a package, e.g. create-react-app.
  5. Having multiple scripts objects in your package.json file.

npm missing script start

shell
npm ERR! Missing script: "start" npm ERR! npm ERR! Did you mean one of these? npm ERR! npm star # Mark your favorite packages npm ERR! npm stars # View packages marked as favorites npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run

To solve the error, make sure to add a start command to the scripts object in your package.json file and open your shell or IDE in the root directory of your project before running the npm start command.

First, make sure your package.json file has a start command in the scripts object.

package.json
{ "scripts": { "start": "node index.js" } }

The start command in your package.json file depends on your setup and the environment your code is run in.

package json scripts section

If you have a start command in the scripts object in your package.json file, make sure you are opening your IDE and shell in the root directory of your project.

You should open your IDE or shell in the directory where your package.json file is to be able to run the npm start command.

If you try to run the command from a different directory, it won't find your package.json file and the Missing script: "start" npm error is caused.

If you don't have a package.json file, create one by opening your terminal in your project's root directory and running the command npm init -y.

shell
npm init -y

Now you can add a start command in the scripts object of your package.json file.

package.json
{ "scripts": { "start": "node index.js", } }
Another cause of the error is having multiple scripts objects in your package.json file.

This causes the error because the second scripts object overrides the first, and your start command might only be present in your first scripts object.

If you don't want to add a start command to the scripts in your package.json file, you can run the command directly from your shell (assuming you have the specific package installed globally).

shell
node index.js

If you use create-react-app, the error might be caused by an outdated version. Open your shell and run the following commands.

shell
# ๐Ÿ‘‡๏ธ Uninstall the old version npm uninstall -g create-react-app # ๐Ÿ‘‡๏ธ clear your cache npx clear-npx-cache # ๐Ÿ‘‡๏ธ to create a normal React.js project npx create-react-app my-app # ๐Ÿ‘‡๏ธ to create TypeScript React.js project npx create-react-app my-app --template typescript

If the suggestions above didn't work, try running the command with the --use-npm flag.

shell
# ๐Ÿ‘‡๏ธ for normal React.js project npx create-react-app@latest my-app --use-npm # ๐Ÿ‘‡๏ธ for TypeScript React.js project npx create-react-app@latest my-app --template typescript --use-npm

# npm ERR! Missing script: "dev"

The npm ERR! Missing script: "dev" error occurs for multiple reasons:

  1. Missing a dev script in the scripts section of your package.json file.
  2. Opening your IDE or shell in a directory that doesn't contain your package.json file.
  3. Not having initialized a package.json file for your project.
  4. Having multiple scripts objects in your package.json file.

npm missing script dev

shell
npm ERR! Missing script: "dev" npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run

To solve the error, make sure to add a dev command to the scripts object in your package.json file and open your shell or IDE in the root directory of your project before running the npm run dev command.

First, make sure your package.json file has a dev command in the scripts object.

package.json
{ "scripts": { "dev": "node index.js" } }

The dev command in your package.json file depends on your setup and the environment your code is run in.

If the command is named something else in your package.json file, you either have to rename it to dev, or run the command with its specified name, e.g. npm run development.

package json scripts section

If you have a dev command in the scripts object in your package.json file, make sure you are opening your IDE and shell in the root directory of your project.

You should open your IDE or shell in the directory where your package.json file is to be able to run the npm run dev command.

If you try to run the command from a different directory, it won't find your package.json file and the Missing script: "dev" npm error is caused.

If you don't have a package.json file, create one by opening your terminal in your project's root directory and running the command npm init -y.

shell
npm init -y

Now you can add a dev command in the scripts object of your package.json file.

package.json
{ "scripts": { "dev": "node index.js", } }
Another cause of the error is having multiple scripts objects in your package.json file.

This causes the error because the second scripts object overrides the first, and your dev command might only be present in your first scripts object.

If you don't want to add a dev command to the scripts in your package.json file, you can run the command directly from your shell (assuming you have the specific package installed globally).

shell
node index.js

# npm ERR! Missing script: "build"

The npm ERR! Missing script: "build" error occurs for multiple reasons:

  1. Missing a build script in the scripts section of your package.json file.
  2. Opening your IDE or shell in a directory that doesn't contain your package.json file.
  3. Not having initialized a package.json file for your project.
  4. Having multiple scripts objects in your package.json file.

npm missing script build

shell
npm ERR! Missing script: "build" npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run

To solve the error, make sure to add a build command to the scripts object in your package.json file and open your shell or IDE in the root directory of your project before running the npm run build command.

First, make sure your package.json file has a build command in the scripts object.

package.json
{ "scripts": { "build": "webpack --config webpack.config.js" } }

The build command in your package.json file depends on your setup and the environment your code is run in.

package json scripts section

If the command is named something else in your package.json file, you either have to rename it to build, or run the command with its specified name, e.g. npm run dist.

If you have a build command in the scripts object in your package.json file, make sure you are opening your IDE and shell in the root directory of your project.

You should open your IDE or shell in the directory where your package.json file is to be able to run the npm run build command.

If you try to run the command from a different directory, it won't find your package.json file and the Missing script: "build" npm error is caused.

If you don't have a package.json file, create one by opening your terminal in your project's root directory and running the command npm init -y.

shell
npm init -y

Now you can add a build command in the scripts object of your package.json file.

package.json
{ "scripts": { "build": "webpack --config webpack.config.js" } }
Another cause of the error is having multiple scripts objects in your package.json file.

This causes the error because the second scripts object overrides the first, and your build command might only be present in your first scripts object.

If you don't want to add a build command to the scripts in your package.json file, you can run the command directly from your shell (assuming you have the specific package installed globally).

shell
webpack --config webpack.config.js

# npm ERR! Missing script: "test"

The npm ERR! Missing script: "test" error occurs for multiple reasons:

  1. Missing a test script in the scripts section of your package.json file.
  2. Opening your IDE or shell in a directory that doesn't contain your package.json file.
  3. Not having initialized a package.json file for your project.
  4. Having multiple scripts objects in your package.json file.

npm missing script test

shell
npm ERR! Missing script: "test" npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run

To solve the error, make sure to add a test command to the scripts object in your package.json file and open your shell or IDE in the root directory of your project before running the npm run test command.

First, make sure your package.json file has a test command in the scripts object.

package.json
{ "scripts": { "test": "jest" } }

The test command in your package.json file depends on your setup.

package-json-scripts-section

If you have a test command in the scripts object in your package.json file, make sure you are opening your IDE and shell in the root directory of your project.

You should open your IDE or shell in the directory where your package.json file is to be able to run the npm run test command.

If you try to run the command from a different directory, it won't find your package.json file and the Missing script: "test" npm error is caused.

If you don't have a package.json file, you have to create one by opening your terminal in your project's root directory and running the command npm init -y.

shell
npm init -y # ๐Ÿ‘‡๏ธ if you need to install `jest` npm install jest --save-dev # or using yarn yarn add jest --dev

Make sure to install all of the packages you use in your project before running the test command.

Now you can add a test command in the scripts object of your package.json file.

package.json
{ "scripts": { "test": "jest" } }
Another cause of the error is having multiple scripts objects in your package.json file.

This causes the error because the second scripts object overrides the first, and your test command might only be present in your first scripts object.

If you don't want to add a test command to the scripts in your package.json file, you can run the command directly from your shell (assuming you have the specific package installed globally).

shell
npx jest

The examples in this article assume you use the jest package as your test runner.

If you haven't installed or configured jest, refer to the Getting Started section in their Github repository.

# npm ERR! Missing script: "lint"

The npm ERR! Missing script: "lint" error occurs for multiple reasons:

  1. Missing a lint script in the scripts section of your package.json file.
  2. Opening your IDE or shell in a directory that doesn't contain your package.json file.
  3. Not having initialized a package.json file for your project.
  4. Having multiple scripts objects in your package.json file.

npm missing script lint

shell
npm ERR! Missing script: "lint" npm ERR! npm ERR! Did you mean this? npm ERR! npm link # Symlink a package folder npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run

To solve the error, make sure to add a lint command to the scripts object in your package.json file and open your shell or IDE in the root directory of your project before running the npm run lint command.

First, make sure your package.json file has a lint command in the scripts object.

package.json
{ "scripts": { "lint": "eslint . --ext js,jsx,ts,tsx --fix" } }

The lint command in your package.json file depends on your setup.

If the command is named something else in your package.json file, you either have to rename it to lint, or run the command with its specified name, e.g. npm run linter.

package json scripts section

If you have a lint command in the scripts object in your package.json file, make sure you are opening your IDE and shell in the root directory of your project.

You should open your IDE or shell in the directory where your package.json file is to be able to run the npm run lint command.

If you try to run the command from a different directory, it won't find your package.json file and the Missing script: "lint" npm error is caused.

If you don't have a package.json file, you have to create one by opening your terminal in your project's root directory and running the command npm init -y.

shell
npm init -y

Now you are able to add a lint command in the scripts object of your package.json file.

package.json
{ "scripts": { "lint": "eslint . --ext js,jsx,ts,tsx --fix" } }
Another cause of the error is having multiple scripts objects in your package.json file.

This causes the error because the second scripts object overrides the first, and your lint command might only be present in your first scripts object.

If you don't want to add a lint command to the scripts in your package.json file, you can run the command directly from your shell (assuming you have the specific package installed globally).

shell
eslint . --ext js,jsx,ts,tsx --fix

The examples in this article assume you use the eslint package to lint your files.

If you haven't installed and set up Eslint in your project, refer to the Installation and Usage and Configuration sections of the eslint package.

# npm ERR! Missing script: "watch"

The npm ERR! Missing script: "watch" error occurs for multiple reasons:

  1. Missing a watch script in the scripts section of your package.json file.
  2. Opening your IDE or shell in a directory that doesn't contain your package.json file.
  3. Not having initialized a package.json file for your project.
  4. Having multiple scripts objects in your package.json file.

npm missing script watch

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

To solve the error, make sure to add a watch command to the scripts object in your package.json file and open your shell or IDE in the root directory of your project before running the npm run watch command.

First, make sure your package.json file has a watch command in the scripts object.

package.json
{ "scripts": { "watch": "webpack --watch --progress" } }

The watch command in your package.json file depends on your setup and the environment your code is run in.

If the command is named something else in your package.json file, you either have to rename it to watch, or run the command with its specified name, e.g. npm run start.

package json scripts section

If you have a watch command in the scripts object in your package.json file, make sure you are opening your IDE and shell in the root directory of your project.

You should open your IDE or shell in the directory where your package.json file is to be able to run the npm run watch command.

If you try to run the command from a different directory, it won't find your package.json file and the Missing script: "watch" npm error is caused.

If you don't have a package.json file, create one by opening your terminal in your project's root directory and running the command npm init -y.

shell
npm init -y

Make sure to install all of the third-party packages your project uses after creating your package.json file.

Now you can add a watch command in the scripts object of your package.json file.

package.json
{ "scripts": { "watch": "webpack --watch --progress" } }
Another cause of the error is having multiple scripts objects in your package.json file.

This causes the error because the second scripts object overrides the first, and your watch command might only be present in your first scripts object.

If you don't want to add a watch command to the scripts in your package.json file, you can run the command directly from your shell (assuming you have the specific package installed globally).

shell
webpack --watch --progress

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev