node.js nodemon 不工作:-bash:nodemon:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35530930/
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 19:57:12  来源:igfitidea点击:

nodemon not working: -bash: nodemon: command not found

node.jsbashexpressnpmnodemon

提问by Brian O'Neill

I'm on a Mac running El Capitan. I have node v5.6.0 and npm v3.6.0. When I try to run nodemon, I get:

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

-bash: nodemon: command not found

I thought this may mean that I didn't have nodemon installed, so when I tried to install it using...

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

sudo npm install -g nodemon

...I get this:

...我明白了:

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

If it makes a difference, I'm trying to run nodemon on a project that uses Express v4.13.1

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

Thanks for any help you can offer!

谢谢你的尽心帮助!

回答by Brian O'Neill

I tried the following, and none worked:

我尝试了以下方法,但都没有奏效:

npm uninstall nodemon

sudo npm uninstall -g nodemon

What did work was:

有效的是:

sudo npm install -g --force nodemon

回答by Alex Leibowitz

If you want to run it locally instead of globally, you can run it from your node_modules:

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

npx nodemon

npx nodemon

回答by Murphy

From you own project.

从你自己的项目。

npx nodemon [your-app.js]

With a local installation, nodemon will not be available in your system path. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as npm start) or using npx nodemon.

对于本地安装,nodemon 在您的系统路径中将不可用。相反,可以通过从 npm 脚本(例如npm start)或使用npx nodemon.

OR

或者

Create a simple symbolik link

创建一个简单的符号链接

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

ln -s [from: where is you install 'nodemon'] [to: folder where are general module for node]

ln -s [来自:你在哪里安装'nodemon'] [至:节点通用模块所在的文件夹]

node : v12.1.0

节点:v12.1.0

npm : 6.9.0

npm : 6.9.0

回答by VnDevil

in Windows OS run:

在 Windows 操作系统中运行:

npx nodemon server.js

or add in package.json config:

或在 package.json 配置中添加:

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

then run:

然后运行:

npm run dev

回答by user2407334

I had the same exact problem, expect for Windows OS.

我有同样的问题,期待 Windows 操作系统。

For me, running

对我来说,跑步

npm install -g nodemon --save-dev

npm install -g nodemon --save-dev

(note the -g) worked.

(注意-g)工作。

Maybe somebody else who has this problem on Windows will have the same solution.

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

回答by syed

For nodemon: not found command I tried with many links but was not working then i tried with the below steps it worked fine.

对于 nodemon: not found 命令,我尝试了很多链接,但都不起作用,然后我尝试了以下步骤,它运行良好。

Follow this step it worked for me.

按照这对我有用的步骤。

step1 : sudo su

第一步:sudo su

step2 : npm install -g nodemon --save-dev

第二步:npm install -g nodemon --save-dev

It is working fine.

它工作正常。

回答by Natesh bhat

I ran into the same problem since I had changed my global path of npm packages before.

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

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 MJ Montes

Just in case for those using Windows, you don't need sudo

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

npm i -g nodemon

回答by Frank Hag

sudo su

then

然后

npm install nodemon 

worked for me

对我来说有效

回答by Akarsh SEGGEMU

In macOS, I fixed this error by installing nodemon globally

在 macOS 中,我通过全局安装 nodemon 修复了这个错误

npm install -g nodemon --save-dev 

and by adding the npm path to the bash_profile file. First, open bash_profile in nano by using the following command,

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

nano ~/.bash_profile

Second, add the following two lines to the bash_profile file (I use comments "##" which makes it bash_profile more readable)

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

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