简体   繁体   中英

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:

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. 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

  • 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.

Just replace nest with npx @nestjs/cli for any command:

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. My npm global installation path was

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

Try installing latest npm using:

npm install npm@latest -g

It worked for me. Also found a related answer here:

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.
  7. Close all pop up windows by clicking OK and that's it.
  8. Close any opened terminal, PowerShell etc.
  9. Open new terminal or PowerShell and type nest -v press 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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