在npm中找不到nodemon
我有一个问题: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`
如何在npm脚本中调用它:
package.json { ... "scripts": { "start": "nodemon server.js" } }
当npm启动脚本运行时:
$ npm start > aaa@0.0.1 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! aaa@0.0.1 start: `nodemon server.js` npm ERR! Exit status 127 npm ERR! npm ERR! Failed at the aaa@0.0.1 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
我一直在寻找一个解决scheme,但没有find一个。
您可以通过向package.json添加nodemon来解决此问题
npm install nodemon --save
nodemon在/node_modules/.bin中不存在时会发生问题
尝试检查已安装的全局程序包npm list -g --depth=0
。 如果您找不到nodemon
,请使用标志-g
或--save-dev
。 不要使用标记--save
安装nodemon
,因为nodemon
仅用于development
。
在您当前的项目目录下运行
npm install nodemon --save //save in package.json so that the following code cam find your nodemon
然后在package.json文件的“scripts”下添加“start”:“nodemon app.js”(或者你的入口点是什么)
所以它看起来像这样:
"scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "nodemon app.js" }
然后运行
npm start
这避免了复杂的path设置,它适用于我的Mac
希望可以帮助你;)
使用以下命令全局安装nodemon
。 它在我的电脑上运行,我相信它也能在你的系统上运行。
npm install nodemon -g --save
有时你应该有权限在全球安装。 这可以通过使用以下命令轻松完成。
-
在LINUX UBUNTU中:
sudo npm install nodemon -g --save
-
在Fedora中:
a)
su
b)npm install nodemon -g --save
我有这个问题,甚至在我使用命令npm install nodemon --save
在我的应用程序中保存后,我仍然遇到了nodemon的问题。
在我全局安装nodemon之后,我使用下面的命令解决了问题: npm install nodemon -g
否则,同样的问题就是一天前工作得很好。 非常简单的修复首先检查您的系统上是否存在全局的nodemon
去检查
npm list -g --depth=0
如果你没有看到,然后安装npm install -g nodemon
(g代表全局)
如果你看到它仍然不起作用,那么你需要configuration我使用Windows操作系统的环境variables。 在Windows上导航到
Control panel>System>Advanced System Settings>Environment Variables>double-click on PATH
现在检查你是否有这个PATH C:\Users\yourUsername\AppData\Roaming\npm
如果没有,你会看到一些现有的path,只是附加到分隔分号。 而已! 为我工作。 对于我来说,节点安装在C:\ Roaming \ npm中,如果PATH不同,你将会放入任何可用的。