Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to solve:npm run build/dev: missing script?

Tags:

npm

I'm trying to run node, but for some reason the local npm install of node isn't working.

The package is there:

$ npm run dev npm ERR! Darwin 15.4.0 
npm ERR! argv "/usr/local/Cellar/node/5.6.0/bin/node" "/usr/local/bin/npm" "run" "jshint" 
npm ERR! node v5.6.0 
npm ERR! npm  v3.6.0
npm ERR! missing script: dev 
npm ERR!  
npm ERR! If you need help, you may report this error at: 
npm ERR!     <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request: 
npm ERR!     /Users/me/workspace/testapp/npm-debug.log

I can work with npm install, but run npm dev is not correct.

like image 723
linkxu1989 Avatar asked Dec 10 '16 03:12

linkxu1989


1 Answers

You saw that error because there was probably not a script named dev in the "scripts" section of your package.json

npm install and npm run dev are two completely different ideas

  1. npm install will run through dependencies section of the package.json and fetch/install the modules in that list

  2. npm run dev will check the scripts section of the package.json and try to find a script titled "dev" and if there is no script named "dev" it will error out as you experienced (Dev is absolutely not a special word by the way, if you ever need to use the scripts section in a future project you can name the scripts anything you want.)

As an example, make a new folder and copy the following into a file named package.json inside of it

{
  "name": "testapp",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "dev": "echo This is the DEV script",
    "abc": "echo This is the abc script",
    "xyz": "echo This is the xyz script",
    "start":"echo This is the special start script"
  }
}

From your terminal, cd into the directory you made containing that sample package.json and try the following commands and see what happens:

npm run dev you should see on your screen "This is the dev script"

npm run abc you see on your scree "This is the abc script"

npm run xyz you should see on your screen "This is the xyz script"

npm run linkxu1989 you should see on your screen a similar error to what you saw above since there's no script named "linkxu1989" in the scripts part of the package.json

npm start you should see on your screen "This is the special start script" (Note that start IS a special name. You can run with just npm start or with npm run start like all the others`

Bottom line: Check the "scripts" section of package.json and to run any of them just enter npm run SCRIPT_NAME

Hope that helps and good luck w/ NPM!

See here for more details

  • https://docs.npmjs.com/getting-started/using-a-package.json

  • http://browsenpm.org/package.json (don't worry about understanding everything in it, all you should think about at this point is what's in "dependencies"

  • http://jsonlint.com/ (If you ever manually edit a package.json, run it through this checker to help catch any formatting mistakes. The package.json is a "json" file so it needs to be in a PERFECT format which means no trailing commas, double quotes only, etc etc)

  • http://www.w3schools.com/js/js_json_syntax.asp

like image 177
Victor Avatar answered Oct 18 '22 02:10

Victor