简体   繁体   English

无法使用 Nest CLI 创建新项目

[英]Unable to create a new project with the Nest CLI

I am following this tutorial to create a nest project.我正在按照教程创建一个嵌套项目。 I have installed Nest CLI using this command:我使用以下命令安装了Nest CLI

npm i -g @nestjs/cli

在此处输入图像描述

I have checked the list of packages installed locally using the following command and found that it was successfully installed:我已经使用以下命令检查了本地安装的软件包列表,发现它已成功安装:

npm list -g --depth 0

在此处输入图像描述

but when I tried to create a new project using following command it gave me an error:但是当我尝试使用以下命令创建一个新项目时,它给了我一个错误:

nest new project-name

Error:错误:

nest: The term 'nest' is not recognized as the name of a cmdlet, function, script file, or operable program. nest:术语“nest”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。 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在行:1 字符:1

  • nest new project-name嵌套新项目名称

  •  + CategoryInfo: ObjectNotFound: (nest:String) [], CommandNotFoundException + FullyQualifiedErrorId: CommandNotFoundException

Screenshot:截屏:

在此处输入图像描述

Why it is so?为什么会这样? What's wrong with it?它出什么问题了? Can someone assist me in identifying the issue?有人可以帮我确定问题吗?

Thanks in advance提前致谢

In most cases, it is better to use npx instead of installing global npm packages, since you'll always use the latest version and not clutter your file system with things you don't need often.在大多数情况下,最好使用npx而不是安装全局 npm 包,因为您将始终使用最新版本,而不会将您的文件系统与您不经常需要的东西混淆。

Just replace nest with npx @nestjs/cli for any command:对于任何命令,只需用npx @nestjs/cli替换nest npx @nestjs/cli

npx @nestjs/cli new project-name

In Windows 10, I was able to resolve this by adding npm installation directory to windows PATH environment variable.在 Windows 10 中,我能够通过将 npm 安装目录添加到 Windows PATH环境变量来解决此问题。 My npm global installation path was我的 npm 全局安装路径是

C:\Users\<user.name>\AppData\Roaming\npm

Try installing latest npm using:尝试使用以下方法安装最新的 npm:

npm install npm@latest -g npm 安装 npm@latest -g

It worked for me.它对我有用。 Also found a related answer here:还在这里找到了相关的答案:

https://github.com/nestjs/nest-cli/issues/223 https://github.com/nestjs/nest-cli/issues/223

For many cases you have to manage environment variables manually.在许多情况下,您必须手动管理环境变量。 For windows;用于窗户;

  1. Right click Start,右键开始,
  2. Click System,点击系统,
  3. Click Advance system settings on the right section under Related settings,单击相关设置下右侧部分的高级系统设置,
  4. System Properties setting will pop up.系统属性设置将弹出。 In Advanced tab, click Environment Variables,在高级选项卡中,单击环境变量,
  5. In user variables search for path variable.在用户变量中搜索路径变量。 Click edit,点击编辑,
  6. Click Browse and find npm folder path ( %AppData%\\Roaming\\npm ) click add.单击浏览并找到 npm 文件夹路径 ( %AppData%\\Roaming\\npm ) 单击添加。
  7. Close all pop up windows by clicking OK and that's it.单击确定关闭所有弹出窗口,就是这样。
  8. Close any opened terminal, PowerShell etc.关闭任何打开的终端、PowerShell 等。
  9. Open new terminal or PowerShell and type nest -v press Enter.打开新终端或 PowerShell 并输入nest -v按 Enter。
  10. If you see the version then everything is fine.如果你看到版本,那么一切都很好。

Install the latest version of node then "nest new project-name" will work.安装最新版本的节点然后“嵌套新项目名称”将起作用。 If it's not the case then use "npx @nestjs/cli new project-name" instead.如果不是这种情况,请改用“npx @nestjs/cli new project-name”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM