[英]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;用于窗户;
%AppData%\\Roaming\\npm
) click add.单击浏览并找到 npm 文件夹路径 ( %AppData%\\Roaming\\npm
) 单击添加。nest -v
press Enter.打开新终端或 PowerShell 并输入nest -v
按 Enter。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.