简体   繁体   English

如何在 package.json 中添加新脚本

[英]How to add a new script in package.json

I want to add a script dev in my package.json .我想在我的package.json添加一个脚本dev

I tried adding it manually in a text editor, but when I run:我尝试在文本编辑器中手动添加它,但是当我运行时:

npm run dev

I get some errors.我得到一些错误。 Is it possible to add the script from the terminal?是否可以从终端添加脚本?


Edit:编辑:

I added:我补充说:

"scripts:" {
  "start": "node app",
  "dev": "nodemon app"
}

and I got this error:我收到了这个错误:

 nodemon app sh: nodemon: command not found npm ERR! code ELIFECYCLE npm ERR! syscall spawn npm ERR! file sh npm ERR! errno ENOENT npm ERR! code@1.0.0 dev: nodemon app npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the code@1.0.0 dev script.

The problem here is you have not installed the package named nodemon :这里的问题是您尚未安装名为nodemon的软件包:

  1. In your CLI enter the following command to install the package:在您的 CLI 中输入以下命令来安装软件包:

     npm install nodemon --save-dev
  2. Then run the following command and it will work:然后运行以下命令,它将起作用:

     npm run dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM