Difference between npm start and npm run start

Npm

Npm Problem Overview


I have checked both commands npm start and npm run start, both works perfectly. I used create-react-app. But to make configuration changes in the CSS module, I run npm eject but it throws an error.

But npm run eject worked? I'm confused on why npm eject didn't work. Can I configure this?

Below is my package.json:

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }

Npm Solutions


Solution 1 - Npm

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.

Solution 2 - Npm

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

Solution 3 - Npm

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLearnerView Question on Stackoverflow
Solution 1 - NpmAKXView Answer on Stackoverflow
Solution 2 - NpmAyushi JainView Answer on Stackoverflow
Solution 3 - NpmVimal MaheedharanView Answer on Stackoverflow