我已经在全球范围内安装了很多次nodemon,但是当我尝试运行它时,它不起作用。这是我收到的错误:
nodemon : The term 'nodemon' is not recognized as the name of a cmdlet,
or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ nodemon server.js
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (nodemon:String) [], CommandN
otFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
我不明白为什么我在全局安装了nodemon后却无法使用它。我在 VSCode 终端中收到此错误,但在 cmd.exe 中收到此错误:
'nodemon' is not recognized as an internal or external command,
operable program or batch file.
我尝试从终端和命令提示符全局安装它。我还尝试删除node_modules和package-lock.json,并通过执行
npm install
重新安装它们。我不明白为什么会发生这种情况,也不知道该怎么办。
使用
npx nodemon
,你的操作系统的环境变量可能已损坏,并且不会链接到 npm 全局包的安装位置。
您的 npm 该模块不支持或与 Nodemon 不兼容,所以 尝试使用
npx
而不是
npm
有趣的是,在 RHEL8.9 和 NodeJS v12.22.0 下,我使用 npm 来启动客户端和服务器实例。 npm 有一个名为 stop 的操作符,但每次都会因缺少脚本错误而失败。例如,根据您的博客,npx 确实可以与 npx stop 服务器正常工作。然而,nodemon 仍然驻留在内存中,并且端口仍然为 nodeman 启用。