node.js 在 npm 中找不到 nodemon
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28517494/
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
nodemon not found in npm
提问by akul
I have a problem: nodemon does not run off the npm script (e.g. npm start),
but if nodemon is called on the command line outside the npm script, nodemon runs as normal.
我有一个问题:nodemon 不会脱离 npm 脚本(例如npm start)运行,
但是如果在 npm 脚本之外的命令行上调用 nodemon,nodemon 会正常运行。
$ nodemon server.js
14 Feb 22:59:51 - [nodemon] v1.3.7
14 Feb 22:59:51 - [nodemon] to restart at any time, enter `rs`
14 Feb 22:59:51 - [nodemon] watching: *.*
14 Feb 22:59:51 - [nodemon] starting `node server.js`
How it is called in npm script:
在 npm 脚本中如何调用它:
package.json
{
...
"scripts": {
"start": "nodemon server.js"
}
}
When npm start script is run:
当 npm start 脚本运行时:
$ npm start
> [email protected] start /home/akul/Documents/aaa
> nodemon server.js
sh: 1: nodemon: not found
npm ERR! Linux 3.13.0-45-generic
npm ERR! argv "node" "/home/akul/npm-global/bin/npm" "start"
npm ERR! node v0.12.0
npm ERR! npm v2.5.0
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `nodemon server.js`
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the [email protected] start script 'nodemon server.js'.
npm ERR! This is most likely a problem with the aaa package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! nodemon server.js
npm ERR! You can get their info via:
npm ERR! npm owner ls aaa
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/akul/Documents/aaa/npm-debug.log
I've been looking for a solution, but have not found one.
我一直在寻找解决方案,但没有找到。
回答by siavolt
You can resolve this problem by adding nodemonto your package.json:
您可以通过添加nodemon到您的package.json:
npm install nodemon --save-dev
The problem happens when nodemondoes not exist in /node_modules/.bin.
nodemon中不存在时会出现问题/node_modules/.bin。
Added --save-devsince it's required during development only.
添加,--save-dev因为它仅在开发过程中需要。
回答by grey87
Try to check installed global packages npm list -g --depth=0. If you will not find nodemon, - install it with flag -gor --save-dev. Don't install nodemonwith flag --save, because nodemonuses only for development.
尝试检查已安装的全局包npm list -g --depth=0。如果找不到nodemon,请使用标志-g或--save-dev. 不要nodemon使用 flag安装--save,因为nodemon仅用于development.
回答by Tina Lee
under your current project directory, run
在您当前的项目目录下,运行
npm install nodemon --save //save in package.json so that the following code cam find your nodemon
then under "scripts" in your package.jsonfile, add "start": "nodemon app.js" (or whatever your entry point is)
so it looks like this:
然后在package.json文件中的“scripts”下,添加“start”:“nodemon app.js”(或任何你的入口点)
,看起来像这样:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
}
and then run
然后运行
npm start
That avoids complicate PATH settings and it works on my mac
hope can help you ;)
这避免了复杂的 PATH 设置,它适用于我的 mac
希望可以帮助你;)
回答by Nilesh Pawar
Install nodemonglobally using following command. It works on my computer, and I'm sure it will work on your system also.
nodemon使用以下命令全局安装。它适用于我的计算机,我相信它也适用于您的系统。
npm install nodemon -g --save
Sometimes you should have the permission to install it globally. It can be easily done by using following command.
有时您应该拥有全局安装它的权限。可以使用以下命令轻松完成。
In LINUX UBUNTU:
sudo npm install nodemon -g --saveIn Fedora:
a)
su
b)npm install nodemon -g --save
在 LINUX UBUNTU 中:
sudo npm install nodemon -g --save在 Fedora 中:
a)
su
b)npm install nodemon -g --save
回答by Imran Pollob
Try to install nodemon globally.
尝试全局安装 nodemon。
sudo npm install -g nodemon
回答by Natesh bhat
Here's how I fixed it :
这是我修复它的方法:
When I installed nodemon using : npm install nodemon -g --save, my path for the global npm packages was not present in the PATH variable .
当我使用 : 安装 nodemon 时npm install nodemon -g --save,我的全局 npm 包路径不存在于 PATH 变量中。
If you just add it to the $PATH variable it will get fixed.
如果您只是将它添加到 $PATH 变量中,它将得到修复。
Edit the ~/.bashrcfile in your home folder and add this line :-
编辑~/.bashrc主文件夹中的文件并添加以下行:-
export PATH=$PATH:~/npm
Here "npm" is the path to my global npm packages . Replace it with the global path in your system
这里的“npm”是我的全局 npm 包的路径。将其替换为系统中的全局路径
回答by Setu Modi
You have to simply installed it globally. npm install -g nodemon
您必须简单地全局安装它。npm install -g nodemon
回答by Mohammad altenji
heroku runs in a production environment by default so it does not install the dev dependencies.
heroku 默认在生产环境中运行,因此它不会安装开发依赖项。
if you don't want to reinstall nodemon as a dependency which I think shouldn't because its right place is in devDependencies not in dependencies.
如果您不想将 nodemon 作为依赖项重新安装,我认为不应该这样做,因为它的正确位置是在 devDependencies 中而不是在依赖项中。
instead, you can create two npm script to avoid this error by running nodemon only in your localhost like that:
相反,您可以创建两个 npm 脚本来避免此错误,方法是仅在您的本地主机中运行 nodemon,如下所示:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",
"start:dev": "nodemon --watch"
},
and when you want to run the project locally just run in your terminal npm run start:devand it will load app.js by nodemon.
当你想在本地运行项目时,只需在你的终端中运行npm run start:dev,它就会通过 nodemon 加载 app.js。
while in heroku npm startruns by default and load app.js from a normal node command and you get rid of that error.
而在 heroku 中npm start默认运行并从普通节点命令加载 app.js 并消除该错误。
回答by younessbennaj
This solution had worked for me:
这个解决方案对我有用:
I assume that you have installed nodemon globally. If it's done follow this steps:
我假设您已经全局安装了 nodemon。如果完成,请按照以下步骤操作:
open your .bash_profile file:
打开您的 .bash_profile 文件:
nano .bash_profile
past this to add a new alias in your bash profile:
通过这个在你的 bash 配置文件中添加一个新的别名:
alias nodemon='~/.npm-global/lib/node_modules/nodemon/bin/nodemon.js'
Now you can use nodemon command anywhere.
现在你可以在任何地方使用 nodemon 命令。
回答by Roshan
sudo npm install nodemon -g --save
Finally this worked for me. I hope this must work for others too
最后这对我有用。我希望这也对其他人有用

