89

我有一个问题: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 start 脚本运行时:

$ 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

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

4

31 回答 31

138

nodemon您可以通过添加到您的来解决此问题package.json

npm install nodemon --save-dev

问题发生在nodemon不存在时/node_modules/.bin

添加--save-dev,因为它仅在开发期间需要。

于 2015-02-14T16:22:03.743 回答
41

尝试检查已安装的全局软件包npm list -g --depth=0。如果找不到nodemon,请使用 flag-g--save-dev. 不要nodemon使用 flag安装--save,因为nodemon仅用于development.

于 2016-09-15T10:13:45.593 回答
36

在您当前的项目目录下,运行

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
希望可以帮助你;)

于 2017-01-12T01:37:06.367 回答
28

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

npm install nodemon -g --save

有时您应该有权在全局范围内安装它。可以使用以下命令轻松完成。

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

  2. 在 Fedora 中:

    一)su
    二)npm install nodemon -g --save

于 2017-06-15T06:35:09.510 回答
11

尝试全局安装 nodemon。

sudo npm install -g nodemon
于 2018-12-31T05:35:03.850 回答
6

这是我修复它的方法:

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

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

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

export PATH=$PATH:~/npm

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

于 2017-12-17T09:58:59.573 回答
3

您必须简单地全局安装它。npm install -g nodemon

于 2018-03-07T11:11:43.413 回答
3

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

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

相反,您可以创建两个 npm 脚本来避免此错误,方法是仅在本地主机中运行 nodemon,如下所示:

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

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

而在 herokunpm start中默认运行并从普通节点命令加载 app.js,您就可以摆脱该错误。

于 2018-12-16T23:26:03.747 回答
2
sudo npm install nodemon -g --save

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

于 2019-10-21T09:08:04.463 回答
2

这个解决方案对我有用:

我假设您已经在全球范围内安装了 nodemon。如果完成,请按照以下步骤操作:

打开你的 .bash_profile 文件:

nano .bash_profile

过去,在您的 bash 配置文件中添加一个新别名:

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

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

于 2018-09-13T18:51:03.240 回答
1

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

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

sudo npm i -g nodemon

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

于 2019-10-04T15:59:12.040 回答
1

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

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

这对我有用!

于 2022-01-03T18:00:58.363 回答
1

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

尝试使用 NPX nodemon ...

希望这可以帮助!

于 2019-01-30T21:52:14.493 回答
1

I faced a similar issue, but then checked .npmrc file and there was incorrect password in that that caused the connection failure and there fore yarn --verbose returned Bad request error. After correcting the password, the packages were added successfully.

于 2020-04-25T08:36:42.673 回答
1

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

我将 node.js 更新到最新版本,现在两者都在工作。

于 2020-05-06T22:30:29.980 回答
1

这对我有用...

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

npm install --save-dev nodemon

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

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

启动nodemonnpm start

$ 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 ...
于 2019-10-20T13:08:19.030 回答
1

我找到了一个非常简单的解决方案。只需从您的 PC 中删除 npm 和 npm 缓存文件夹即可。重新安装一遍,但是我们很多人犯的错误是没有全局安装npm。所以:

npm i -g npm

然后,全局安装 nodemon:

npm i -g nodemon

现在,nodemon 在全局范围内工作,即使不使用以下命令:

npx nodemon <yourfilename>.js
于 2020-04-29T04:59:47.730 回答
1

对于带有适用于 Linux 的 Windows 子系统的 Visual Studio Code 编辑器,即 WSL 模式:

sudo npm install nodemon -g

用于 nodemon 的全局使用。

于 2020-06-29T13:56:46.343 回答
0

--save、-g 和更改 package.json 脚本对我不起作用。这是做的:在命令行中运行npm start(或使用)。npx nodemon我使用视觉工作室代码终端。成功后你会看到这样的信息:

[nodemon] 1.18.9
[nodemon] 随时重启,输入rs
[nodemon] watch:
[nodemon] 开始node app.js

祝你好运!

于 2019-01-15T00:53:57.067 回答
0

首先将 nodemon 安装到您的工作文件夹

npm install nodemon

将 nodemon 的路径添加到System environment 的 Environment Variable 的路径变量中。就我而言,nodemon 的路径是。

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

它对我有用。

于 2018-06-21T09:01:35.880 回答
0

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

heroku 配置:设置 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"
 }

希望它会有所帮助:)

于 2020-10-30T12:57:09.763 回答
0

我的情况:

npm install nodemon

没有任何标志等。

于 2020-04-21T20:02:18.297 回答
0

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

于 2019-12-19T05:08:43.347 回答
0

对于 linux 试试

sudo npm install -g nodemon

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

npm install -g nodemon
于 2020-05-31T20:11:29.003 回答
0


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

去检查

npm list -g --depth=0

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

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

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

于 2017-09-28T17:44:41.040 回答
0

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

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

我希望这可以帮助任何一直在努力解决这个问题的人!

于 2018-10-08T10:11:10.980 回答
0

我遇到了这个问题,即使在npm install nodemon --save我的应用程序中使用了该命令,我仍然遇到 nodemon 问题。

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

于 2017-05-11T23:19:52.173 回答
0

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

于 2021-09-27T15:18:01.967 回答
0

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

于 2018-07-03T14:14:24.107 回答
0

用于 Windows 的说明,

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

于 2019-12-26T10:50:06.533 回答
0

在我的情况下 nodemon 需要全局安装:

npm i nodemon -g --save
于 2019-11-16T06:37:44.580 回答