(Windows) 如何修复 nodemon | Node.js

(Windows) How to fix nodemon | Node.js

所以我前一阵子开始用nodemon,最近又开始用了。但是我从 VS-Code 命令行得到一个错误:

The term 'nodemon' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ nodemon
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (nodemon:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

这基本上意味着它不是命令,在实际的 cmd 中会发生类似的事情。

编辑:我做这个问答只是为了一些有同样问题的人。

如果出现此错误,这可能意味着您尚未安装 nodemon,或者它不在名为 'Path' 的环境变量中。我假设你确实做了 npm install -g nodemon。否则我不知道你在这里做什么。此外,这将是一个非常 in-depth 的答案

所以首先,您想转到 Windows 中的搜索栏。然后输入; “环境”。

之后,你想点击"Edit the system environment variables"。是self-explanatory,是系统环境的变量。

然后,您要单击“环境变量”。一个window会弹出很多东西,你要在系统变量中找到那个叫'Path'的变量:

然后您想要 select 它并单击“编辑”。然后将打开一个选项卡;对于变量的内容,我使用的是 Windows 的 10.0.18363 版本,你的可能看起来和我的不一样。但是您想添加一个新变量。如果你有这个变量 C:\Users\yourUsername\AppData\Roaming\npm 并且 nodemon 仍然不起作用,你可以跳过这一步。否则你会看到列出的其他路径,只需附加到它,用分号分隔。

例如,假设列出的最后一个路径是“C:\Windows\System32”。我会添加一个“;”,然后是 nodemon 的路径,因此最终结果将如下所示:"C:\Windows\System32;C:\Users\dawoo\AppData\Roaming\npm".

之后,您要单击 OK,然后再次单击 OK。你现在应该没事了。如果您仍然遇到问题,就像我一样,您想要在 Windows 按钮上 right-click,然后单击:"Windows PowerShell (Admin)"。您想要 分别 复制和粘贴三个东西。我为 1 和 2 按了“A”(全部是),这可能不起作用,所以请尝试“是”,即“Y”。

  1. ) Set-ExecutionPolicy RemoteSigned

  2. ) Set-ExecutionPolicy Unrestricted

  3. ) Get-ExecutionPolicy

键入 Get-ExecutionPolicy 后,您应该会看到“Unrestricted”或“RemoteSigned”之类的内容。现在,nodemon 应该可以工作了!我只是想做这个问答 post 因为我看到很多人在 Discord 上私信我说 nodemon 不起作用,我也想帮助其他偶然发现这个问题的人。祝您一天愉快。

编辑:OverFlow 没有保存我的更改,希望你能看到这个,但我从我的一位朋友那里找到了解决这个问题的方法。