如何解决:npm run build/dev:缺少脚本? [英] how to solve:npm run build/dev: missing script?

查看:341
本文介绍了如何解决:npm run build/dev:缺少脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行节点,但由于某种原因,节点的本地 npm 安装不起作用.

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

包裹在那里:

$ 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

我可以使用 npm install,但是 run npm dev 不正确.

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

推荐答案

您看到该错误是因为您的 package.json 的脚本"部分中可能没有名为 dev 的脚本

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

npm installnpm run dev 是两个完全不同的想法

npm install and npm run dev are two completely different ideas

  1. npm install 将运行 package.json 的 dependencies 部分并获取/安装该列表中的模块

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

npm run dev 将检查 package.json 的 scripts 部分并尝试找到一个名为dev"的脚本,如果没有名为dev"它会在你遇到的时候出错(顺便说一下,Dev 绝对不是一个特殊的词,如果你需要在未来的项目中使用脚本部分,你可以随意命名脚本.)

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.)

举个例子,新建一个文件夹,把下面的内容复制到里面的名为package.json的文件中

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"
  }
}

从您的终端,cd 进入您创建的包含示例 package.json 的目录,然后尝试以下命令,看看会发生什么:

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 你应该在屏幕上看到这是开发脚本"

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

npm run abc 你在你的屏幕上看到这是 abc 脚本"

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

npm run xyz 你应该在屏幕上看到这是 xyz 脚本"

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

npm run linkxu1989 您应该在屏幕上看到与上面看到的类似的错误,因为 package.json 的脚本部分中没有名为linkxu1989"的脚本

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 你应该在你的屏幕上看到这是特殊的启动脚本"(注意 start 是一个特殊的名字.你可以只用 npm start 运行或者与 npm run start 一样`

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`

底线:检查 package.json 的脚本"部分并运行它们中的任何一个,只需输入 npm run SCRIPT_NAME

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

希望对 NPM 有所帮助并祝您好运!

Hope that helps and good luck w/ NPM!

点击此处了解更多详情

http://browsenpm.org/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/(如果您曾经手动编辑过 package.json,请运行它通过这个检查器来帮助捕捉任何格式错误.package.json 是一个json"文件,所以它需要采用完美的格式,这意味着没有尾随逗号,只有双引号等)

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

这篇关于如何解决:npm run build/dev:缺少脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆