238

I am able to run both the npm start and npm run start commands. I used create-react-app to create my application. To make configuration changes in the CSS module, I want to run npm eject but it throws an error.

The npm run eject command works however. I'm confused as to why npm eject did not work. Can I configure it to work?

Below is my package.json file:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
}
Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
Learner
  • 8,379
  • 7
  • 44
  • 82

4 Answers4

430

npm test, npm start, npm restart, and npm stop are all aliases for npm run xxx.

For all other scripts you define, you need to use the npm run xxx syntax.

See the docs at https://docs.npmjs.com/cli/run-script for more information.

Reg Edit
  • 6,719
  • 1
  • 35
  • 46
AKX
  • 152,115
  • 15
  • 115
  • 172
33

npm start is the short form for npm run start. So, its one and the same thing.

Ayushi Jain
  • 828
  • 8
  • 17
15

One interesting thing to note is,
If the scripts object does not have a "start" property in package.json file, npm start or npm run start from command line will run node server.js by default.

But if the scripts object in package.json has "start" property, it overrides node server.js and executes the command in "start" property.

See - https://docs.npmjs.com/cli/v7/commands/npm-start#description

3

Telling this because sometimes this can be help to someone. Inside the jenkins pipelines you should use npm commands with "run" ex- npm run start if not the command will not be executed.

  • 1
    It's actually any minimal environment where you are lacking things like stdout (a true tty), such as in a minimal or stipped container. In these cases many aliases are actually non-existent; For example, when using Jenkins, Tavis-CI, or GitLab-CI, in various versions of their runners and containers - even with self-installed Node, you will find `npm test` fails with an error that the command is not found, and you'll need to set `npm run test`. This is a good point to make, so I upvoted you - its just not an answer to the question (obviously). – Rik Nov 27 '22 at 03:42