node.js 如何解决 npm run dev 缺少脚本问题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41129815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:52:03  来源:igfitidea点击:

How to resolve npm run dev missing script issues?

node.jswebpackgit-bash

提问by user3804335

I am currently in the folder 'C:\Users\vignesh\Documents\Personal Projects\Full-Stack-Web-Developement' on gitbash

我目前在 gitbash 的文件夹“C:\Users\vignesh\Documents\Personal Projects\Full-Stack-Web-Developement”中

npm run dev

npm 运行开发

executing the above command on gitbash gives me the following error. I am assuming this is due to the NODE_PATH variables not being set properly. Please let me know if anyone has a solution to the below problem

在 gitbash 上执行上述命令给了我以下错误。我假设这是由于没有正确设置 NODE_PATH 变量。请让我知道是否有人解决了以下问题

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "dev"
npm ERR! node v4.4.6
npm ERR! npm  v2.15.5

npm ERR! missing script: dev

回答by Micha? Ignaszewski

npm run <command>

will run bash script from package.json from 'scripts' value of '' attribute. For example:

将从 package.json 的 'scripts' '' 属性值运行 bash 脚本。例如:

package.json

包.json

{
   "name": "app",
   "version": "0.0.0",
   "license": "MIT",
   "scripts": {
      "server": "webpack-dashboard -- webpack-dev-server --inline --port 8080",
      "webdriver-update": "webdriver-manager update",
   },
  "dependencies": {
   "@angular/common": "~2.2.0",
   "@angular/core": "~2.2.0"
   },
  "devDependencies": {
   "@types/core-js": "^0.9.0"
   }
}

In this case you can run scripts:

在这种情况下,您可以运行脚本:

npm run server
npm run webdriver-update

In your case you probably wont have devscript.

在您的情况下,您可能没有开发脚本。

Remember that few scripts name are reserved (for example npm testwill try to run, npm run pretest, npm run test, npm run posttest). More info on https://docs.npmjs.com/misc/scripts

请记住,保留了一些脚本名称(例如npm test将尝试运行、npm run pretest、npm run test、npm run posttest)。有关https://docs.npmjs.com/misc/scripts 的更多信息

回答by Zoh_Akh

Simply check the package.json file and see what the name of the key is for dev. In my case it was start instead of dev, so I ran npm run startand that did it.

只需检查 package.json 文件并查看 dev 的密钥名称。在我的情况下,它是 start 而不是 dev,所以我跑了npm run start,它做到了。

Screenshot:

截屏:

Screenshot

截屏

回答by user11746231

1) In the npm package.json script, define a script like this:

1) 在 npm package.json 脚本中,定义一个这样的脚本:

"start:dev": "webpack-dev-server --open --config webpack/webpack.config.dev.js, 

Note: if it is not the last statement ends with a comma.

注意:如果不是最后一个语句,则以逗号结尾。

2) run the below statement in terminal

2)在终端中运行以下语句

npm run start:dev

回答by chanaka wickramasinghe

Check the package.json file and see whether it is dev. I face the exact problem and in my case, it started. so I used the command npm run startand it worked.

检查 package.json 文件,看看它是否是 dev。我面临着确切的问题,就我而言,它开始了。所以我使用了命令npm run start并且它起作用了。

enter image description here

在此处输入图片说明

回答by Cristina Rodrigues da Costa Me

After you install:

安装后:

npm install --save-dev nodemon

Go in the package.json and add "dev": "nodemon ./bin/www"

进入 package.json 并添加 "dev": "nodemon ./bin/www"

回答by RileyManda

Adding

添加

"scripts": {
   "dev": "nodemon server.js",

},

},

to your package.jsonresolves the problem.

到您的package.json解决了问题。