nodemon无法正常工作:-bash:nodemon:command not found

问题描述 投票:16回答:10

我在Mac上运行El Capitan。我有节点v5.6.0和npm v3.6.0。当我尝试运行nodemon时,我得到:

-bash: nodemon: command not found

我认为这可能意味着我没有安装nodemon,所以当我尝试使用...时安装它

sudo npm install -g nodemon

......我明白了:

npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g"     "nodemon"
npm ERR! node v5.6.0
npm ERR! npm  v3.6.0
npm ERR! path /usr/local/bin/nodemon
npm ERR! code EEXIST

npm ERR! Refusing to delete /usr/local/bin/nodemon: ../lib/node_modules/nodemon/nodemon.js symlink target is not controlled by         npm /usr/local
npm ERR! File exists: /usr/local/bin/nodemon
npm ERR! Move it away, and try again.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/brianeoneill/npm-debug.log

如果它有所作为,我正在尝试在使用Express v4.13.1的项目上运行nodemon

谢谢你尽你所能的帮助!

node.js bash express npm nodemon
10个回答
37
投票

我尝试了以下,没有一个工作:

npm uninstall nodemon

sudo npm uninstall -g nodemon

工作是什么:

sudo npm install -g --force nodemon

11
投票

如果要在本地而不是全局运行它,可以从node_modules运行它:

npx nodemon


2
投票

我遇到了同样的问题,因为之前我已经改变了我的npm包的全局路径。

Here's how I fixed it :

当我使用:npm install nodemon -g --save安装nodemon时,我的路径全局npm包在PATH变量中不存在。

如果你只是将它添加到$ PATH变量,它将得到修复。

编辑主文件夹中的~/.bashrc文件并添加以下行: -

export PATH=$PATH:~/npm

这里“npm”是我的全局npm包的路径。将其替换为系统中的全局路径


2
投票

来自你自己的项目。

npx nodemon [your-app.js]

使用本地安装,nodemon将不会在您的系统路径中可用。相反,可以通过在npm脚本(例如npm start)或使用npx nodemon中调用nodemon来运行nodemon的本地安装。

要么

创建一个简单的符号链接

ln -s /Users/YourUsername/.npm-global/bin/nodemon /usr/local/bin

ln -s [来自:你在哪里安装'nodemon'] [to:文件夹,其中是节点的通用模块]

所以:v12.1.0

海拔:6.9.0


1
投票

对于Windows操作系统,我有同样的问题。

对我来说,跑步

npm install -g nodemon --save-dev

(注意-g)有效。

也许在Windows上遇到此问题的其他人也会有相同的解决方案。


1
投票

在macOS中,我通过全局安装nodemon来修复此错误

npm install -g nodemon --save-dev 

并将npm路径添加到bash_profile文件中。首先,使用以下命令打开nano中的bash_profile,

nano ~/.bash_profile

其次,将以下两行添加到bash_profile文件中(我使用注释“##”,这使得bash_profile更具可读性)

## npm
export PATH=$PATH:~/npm

1
投票

确保您拥有npm的根目录,这样您在不使用sudo的情况下安装全局包时就不会出现任何错误。

程序: - 在根目录中

sudo chown -R yourUsername /usr/local/lib/node_modules
sudo chown -R yourUsername /usr/local/bin/
sudo chown -R yourUsername /usr/local/share/

所以现在用

npm i npm -g 

你没有错误,也没有使用sudo。但是如果仍然出现错误,请确认node_modules再次拥有

/usr/local/lib/

并确保你拥有一切

ls -la

enter image description here现在

npm i -g nodemon

将工作!


0
投票
sudo su

然后

npm install nodemon 

为我工作


0
投票

以防万一使用Windows,你不需要sudo

npm i -g nodemon
© www.soinside.com 2019 - 2024. All rights reserved.