在 npm 中找不到 nodemon

nodemon not found in npm

我有一个问题:nodemon 没有 运行 关闭 npm 脚本(例如 npm start),
但是如果在 npm 脚本之外的命令行上调用 nodemon,nodemon 运行s 正常。

$ 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 start script 为 运行:

$ 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

我一直在寻找解决方案,但一直没有找到。

您可以通过将 nodemon 添加到您的 package.json:

来解决此问题
npm install nodemon --save-dev

nodemon/node_modules/.bin 中不存在时会出现问题。

已添加 --save-dev 因为它仅在开发过程中需要。

尝试检查已安装的全局包 npm list -g --depth=0。如果您找不到 nodemon,- 使用标志 -g--save-dev 安装它。不要安装带有标记 --savenodemon,因为 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
希望能帮到你 ;)

我遇到了这个问题,甚至在我的应用程序中使用了命令 npm install nodemon --save 之后,nodemon 仍然有问题。

我在全局安装nodemon后才解决,使用命令:npm install nodemon -g

使用以下命令全局安装 nodemon。它适用于我的计算机,我相信它也适用于您的系统。

npm install nodemon -g --save

有时候你应该有全局安装的权限。使用以下命令可以轻松完成。

  1. 在LINUXUBUNTU中: sudo npm install nodemon -g --save

  2. 在 Fedora 中:

    a) su
    b)npm install nodemon -g --save


有同样的问题,否则一天前工作正常。 非常简单的修复 首先检查 nodemon 是否全局存在于您的系统上

To check

npm list -g --depth=0

如果您没有看到,请安装 it npm install -g nodemon (g代表全局)
如果你看到它仍然不起作用那么你需要配置环境变量 我使用 Windows OS. 在 Windows 上导航到

Control panel>System>Advanced System Settings>Environment Variables>double-click on PATH

现在检查你是否有这个 PATH C:\Users\yourUsername\AppData\Roaming\npm
如果没有,您会看到一些现有的路径,只需附加到它上面,用分号分隔。而已! 对我有用。 对我来说,节点安装在 C:..\Roaming\npm 中,对你来说,如果 PATH 不同,你将放入任何适用的电缆。

这是我修复它的方法:

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

如果您将它添加到 $PATH 变量中,它将得到修复。

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

export PATH=$PATH:~/npm

这里 "npm" 是我的全局 npm 包的路径。替换为你系统中的全局路径

您只需在全局安装即可。 npm install -g nodemon

首先通过

将nodemon安装到您的工作文件夹
npm install nodemon

将nodemon的路径添加到系统环境的环境变量路径变量中。 在我的例子中,nodemon 的路径是。

C:\Users\Dell\Desktop\Internship Project\schema\node_modules\.bin

它对我有用。

您可以随时重新安装 Node.js。当我遇到这个问题时,我无法修复它,但我所做的只是更新当前版本的 Node。您可以使用 link 更新它:https://nodejs.org/en/download/

这个解决方案对我有用:

我假设你已经全局安装了nodemon。如果完成,请按照以下步骤操作:

打开您的 .bash_profile 文件:

nano .bash_profile

在您的 bash 个人资料中添加新别名:

alias nodemon='~/.npm-global/lib/node_modules/nodemon/bin/nodemon.js'

现在你可以在任何地方使用nodemon 命令了。

我想补充一下我是如何解决这个问题的,因为我必须混合搭配几种不同的解决方案。作为参考,这是针对 Windows 10 PC 的,nodemon 已经完美运行了几个月,然后突然找不到命令,除非 运行 在本地使用 npx。 这是我的步骤 -

  1. 检查它是否由 运行ning npm list -g --depth=0 全局安装,在我的情况下它已安装,所以重新开始...
  2. 我运行npm uninstall -g nodemon
  3. 接下来,我使用 npm install -g --force nodemon --save-dev 重新安装(可能建议先尝试 运行ning npm install -g nodemon --save-dev,完成其余步骤,如果它不起作用使用 --force.
  4. 再次执行步骤 2 和 3
  5. 然后我使用命令 npm config get prefix 检查了我的 npm 文件夹的位置,在我的例子中它位于 C:\Users\username\AppData\Roaming\npm
  6. 我修改了我的 PATH 变量以添加该文件路径和附加了 \bin 的第二个条目(我不确定实际需要哪个条目,因为有些人只需要根 npm 文件夹,而其他人则需要bin,简单地添加两者就足够了)
  7. 最后,我遵循了与 Natesh 在此条目上推荐的类似的指示,但是,对于 Windows,.bashrc 文件不会自动存在,因此您需要在您的 ~ 目录中创建一个。我还需要稍微更改导出的写入方式 export PATH=%PATH%;C:\Users\username\AppData\Roaming\npm;(显然将 "username" 替换为您的用户名或在第 4 步中检索到的任何文件路径)

我希望这对像我一样一直在为这个问题苦苦挣扎的人有所帮助!

heroku 运行默认情况下在生产环境中,因此它不会安装开发依赖项。

如果您不想将 nodemon 作为依赖项重新安装,我认为不应该,因为它的正确位置是在 devDependencies 中而不是在 dependencies 中。

相反,您可以通过 运行仅在您的本地主机中使用 nodemon 来创建两个 npm 脚本来避免此错误:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js",
    "start:dev": "nodemon --watch"
},

并且当您想要 运行 本地项目时,只需 运行 在您的终端 npm run start:dev 中,它将由 nodemon 加载 app.js。

在 heroku npm start 运行s 默认情况下,从普通节点命令加载 app.js,你就摆脱了那个错误。

尝试全局安装nodemon。

sudo npm install -g nodemon

--save、-g 和更改 package.json 脚本对我不起作用。这是所做的:运行 npm start(或使用 npx nodemon)在命令行中。我使用 visual studio 代码终端。 成功后您将看到此消息:

[nodemon] 1.18.9
[nodemon] 随时重启,输入rs
[nodemon] 正在观看:.
[nodemon] 开始 node app.js

祝你好运!

NPM 用于管理包和下载它们。但是必须使用NPX作为执行Node Packages的工具

尝试使用 NPX nodemon ...

希望对您有所帮助!

我的 nodemon 在安装 babel 后消失了(为什么?)。

尝试了很多东西。 这是我解决它的方法:

sudo npm i -g nodemon

只需使用 sudo 重新安装即可。是的。

这对我有用...

将 nodemon 安装为本地开发依赖项

npm install --save-dev nodemon

将脚本添加到您的应用程序package.json以启动应用程序。

"scripts": {
  "start": "nodemon app.js"
},

npm start

启动nodemon
$ npm start

> node-rest-demo@1.0.0 start node-rest-demo
> nodemon app.js

[nodemon] 1.19.4 [nodemon] to restart at any time, enter `rs` [nodemon] watching dir(s): *.* [nodemon] watching extensions: js,mjs,json [nodemon] starting `node app.js` Starting server ...
sudo npm install nodemon -g --save

最后这对我有用。我希望这也适用于其他人

在我的例子中,nodemon 需要全局安装:

npm i nodemon -g --save

我尝试使用 npm list -g --depth=0 列出全局包,但找不到 nodemon。
因此,尝试使用全局标志安装它。
sudo npm install nodemon -g
这对我来说很好。

Windows、

的说明

打开命令提示符。
输入 npm i -g nodemon --save
“--save”是将这个节点包的添加保存到你项目的package.json文件

我的情况:

npm install nodemon

没有任何标志等

我遇到了类似的问题,但随后检查了 .npmrc 文件,发现密码不正确导致连接失败,因此 yarn --verbose 返回了 Bad request 错误。修改密码后,包添加成功

我找到了一个非常简单的解决方案。 只需从您的电脑中删除 npm 和 npm 缓存文件夹。 重新安装一遍,但是我们很多人犯的错误就是没有安装npm globally.So:

npm i -g npm

然后,全局安装nodemon:

npm i -g nodemon

现在,即使不使用命令,nodemon 也可以在全球范围内工作:

npx nodemon <yourfilename>.js

npx nodemon (app.js) 为我工作而 nodemon (app.js) 没有。

我已将 node.js 更新到最新版本,现在两者都可以使用。

为了linux尝试

sudo npm install -g nodemon

对于windows 打开 powershell 或 cmd 作为管理

npm install -g nodemon

Visual Studio 代码编辑器 Windows Linux 子系统,即 WSL 模式:

sudo npm install nodemon -g

全球使用 nodemon。

我在 Heroku 上部署时遇到了这个问题。 问题出在 Heroku 上,它本身不包含 devDependencies。 要解决此问题,只需 运行 终端中的命令:

heroku config:set NPM_CONFIG_PRODUCTION=false

确保在你的 devDependencies 中包含 nodemon

"devDependencies": {
    "nodemon": "^2.0.6"
  }

如果你的错误不在 Heroku 中

我建议卸载 nodemon 然后重新安装它

https://www.npmjs.com/package/nodemon

或尝试更改脚本

"scripts": {
    "start": "nodemon fileName.js",
    "start:dev": "nodemon fileName.js"
 }

希望对您有所帮助:)

nodemon --watch contracts --exec "truffle compile" contracts/Presale.sol

我遇到了同样的问题并且能够解决它。这是我的错误:

npm install -g nodemon
npm WARN checkPermissions Missing write access to /usr/local/lib
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/nodemon/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/rayani00/.npm/_logs/2022-01-03T17_50_15_842Z-debug.log
(base) rayani00@rayani00:~/Bureau/my-express-server$ npm cache clear --force
npm WARN using --force I sure hope you know what you are doing.

为了解决这个问题,我刚刚为 nodemon 安装添加了一个 sudo :

  1. sudo npm install -g nodemon
  2. nodemon server.js

这对我有用!