nest Command not found
Asked Answered
F

17

35

I followed the documentation to create my first NestJS project.

Installing the Nest CLI with the command npm i -g @nestjs/cli was successful.

The output was:

+ @nestjs/[email protected]
updated 1 package in 11.326s

However, when I try to scaffold a project with the Nest CLI:

nest new project-name

I get the following error:

zsh: command not found: nest

Some details about my environment:

  • OSX
  • iTerm
  • npm version 6.5.0
Filia answered 23/4, 2019 at 6:11 Comment(0)
B
54

Use npx @nestjs/cli instead of nest

e.g. npx @nestjs/cli g controller pages

Borisborja answered 16/11, 2020 at 15:28 Comment(0)
H
16

I was also getting the same console error when npm installing!

Error was

@nestjs/cli
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/@nestjs/cli
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/@nestjs
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":"<8.10.0"} (current: {"node":"12.14.1","npm":"6.13.4"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]

How I was able to install:

Solution

sudo npm install -g @nestjs/cli
Homologize answered 11/10, 2020 at 7:32 Comment(3)
Never, ever, use SUDO with NPM as it may lead to security issuesThomsen
care to elaborate on that? Anyway, installing a package globally requires elevated rights. Is there a way around this?Rake
ok, here it is: github.com/sindresorhus/guides/blob/main/…Rake
H
7

Following command works in my windows 10

node -v 
v14.16.0
 
npm -v
6.14.11

npx @nestjs/cli new project-name
Helfrich answered 26/5, 2021 at 9:37 Comment(0)
R
3

I was having the same issue, what I did was:

Installed the latest node with npm install npm@latest -g

and then added the following to my .bash_profile

alias nest="/usr/local/Cellar/node/11.9.0/bin/nest"

Tested with nest --version and it worked.

For some reason the path is not being called correctly, hope it helps.

Roadbed answered 12/5, 2019 at 15:5 Comment(1)
Please note that this wont work since he's using zsh and not bash. He need to do the equivalent for his ~/.zshrc.Reckless
C
2

After all the answers that I tried, I used my method

  1. After installing npm i -g @nestjs/cli in my mac terminal.

  2. open bash file in macos by typing open ~/.bash_profile in mac terminal. Like you can type it anywhere.

  3. Your bash will look like this, the highlighted area is for nest js cli Your bash will look like this and use this line

    alias nest="~/.npm-global/lib/node_modules/@nestjs/cli/bin/nest.js"

  4. Restart your mac for changes to be reflected in your terminal.

  5. There you go nestjs cli is now working globally 2nd screenshot. Should look like this

Consonant answered 27/4, 2022 at 17:15 Comment(0)
H
1

Working through a NestJS/Mongo DB tutorial i stumbled into this very same problem. After trying all of the solutions that were listed above, even turning my default profile back to bash instead of using zsh, i found that simply adding the /usr/local/bin and ~/.npm-global/bin to my path variable resolved the issue. Hopefully this helps someone else who may stumble on this in the future as well.

export $PATH="/usr/local/bin"

export $PATH="~/.npm-global/bin"

Were the two commands i ran from iTerm2 in order to add them to my PATH environment variable. Once this was done a simple

env

showed the entries in my $PATH environment variable and the nest -v command worked without any issues.

Howard answered 27/5, 2021 at 1:21 Comment(0)
J
1

I had same error when I use GitBash. I resoved it: If you use windows: Your use CMD: npm i -g @nestjs/cli

Then you can use gitbash:

  • Check version nestjs: nest --version
  • Create app nestjs: nest new name_project
Jellify answered 17/7, 2021 at 17:33 Comment(0)
R
1

I have faced same problem and solved ,following this

  1. write the command NPM root -g
  2. check where NPM is installed
  3. add it to your path environment variable
Rosierosily answered 12/12, 2021 at 5:55 Comment(0)
K
1

This worked for me:

npm install @nestjs/cli --global

then

nest

will be available

Kilmarx answered 29/8, 2023 at 19:29 Comment(0)
M
0

You have to add the following line to your ~/.zshrc file:

source $HOME/.bashrc

This is needed so that the npm binaries are available on startup.

Molecule answered 24/4, 2019 at 13:45 Comment(1)
Still the same outcome. What worked is to add alias nest="/usr/local/lib/node_modules/node/lib/node_modules/node/lib/node_modules/@nestjs/cli/bin/nest.js to my ~/.zshrc file. But not sure it is the best solution as a future npm will need an additional alias.Backset
G
0

I have just succeeded with npx @nets/cli new project when asked what manager to choose from npm / yarn / pnpm made choice for pnpm cd project npm run start Take care!

Gink answered 9/7, 2022 at 8:5 Comment(0)
F
0

Must use sudo in comandline for linux, otherwise the command nest cannot be add to /usr/local/bin folder: sudo npm install -g @nestjs/cli

Faery answered 18/1, 2023 at 4:27 Comment(0)
S
0

updating node version to 16 or more will help. I solved the issue by doing this.

nvm use 16^

Squamulose answered 27/4, 2023 at 7:37 Comment(0)
G
0

I had the same problem

I tried all the command to delete npm proxy and all

But nothing helped me.

In many cases some other services are blocking your network like your antivirus

you can try installing by restarting the system. this also help take effect of the commands you ran like the npm config to delete proxy

Simple thing try re-starting and installing your Nest js again.

it helped in my case probably will help you as well !

Gassman answered 26/10, 2023 at 15:57 Comment(0)
P
0

I added this from my .bash_profile and it helped

export PATH=~/.npm-global/bin:$PATH
Pearliepearline answered 30/11, 2023 at 14:10 Comment(0)
P
-1

If you have an existing project at first install libraries

npm install 

then build

nest build
Pacesetter answered 7/3, 2023 at 18:34 Comment(0)
U
-2

You can try to use sudo

sudo yarn global add @nestjs/cli
Unconformity answered 8/5, 2020 at 9:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.