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

2020-03-12 04:35发布

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.

标签: npm
1条回答
做自己的国王
2楼-- · 2020-03-12 05:15

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

查看更多
登录 后发表回答