Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zsh: command not found: nx

I am trying to create a library in Angular using nx g @nrwl/angular:lib shared but it keep giving me error zsh: command not found: nx. All I did was before just create a angular project. I try using this: npm install -g nx so maybe it install nx and it works, but I still keep getting the same error.

How can I fix this? I am using Mac. If any questions or information needed please feel free to leave the comment down below.

like image 394
Hem Avatar asked Nov 30 '20 06:11

Hem


People also ask

What is NX command?

The nx run command executes a target on a single project. For convenience, you can also run nx [target] [project] which is an alias to nx run [project]:[target] .

What is NX in angular?

Nx is a smart, fast and extensible build system with first class monorepo support and powerful integrations. It has a powerful core and a rich plugin ecosystem.

How to find the path of Zsh shell in Linux?

Then go to the profile tab and go down to command. As you can see on the picture below, you need to select command option and paste path of zsh shell (to find the path, you can do which zsh ).

What is command not found handler in zsh?

When a command is not found, zsh invokes the function command_not_found_handler. A typical use for this function is to suggest a way to install the command, if it's part of a package that's part of your distribution but isn't installed. In zsh, if the function returns a nonzero status, zsh prints its usual error message.

How do I solve the NX Command not found error?

Use npx to solve the error "nx: command not found", e.g. npx nx or install the package globally by running npm install -g @nrwl/cli to be able to use the command without the npx prefix. The fastest way to solve the error is to use the npx command. Alternatively, you can install @nrwl/cli globally.

What is the use of nonzero error in zsh?

A typical use for this function is to suggest a way to install the command, if it's part of a package that's part of your distribution but isn't installed. In zsh, if the function returns a nonzero status, zsh prints its usual error message.


5 Answers

sudo npm install -g nx fixed, sudo might be needed...

like image 102
Daniel Danielecki Avatar answered Nov 02 '22 12:11

Daniel Danielecki


Try this: Install it globally by below command 100% will work

sudo npm i -g @nrwl/cli

remove -g if you don't want to install globally.

like image 25
Mahaveer Avatar answered Nov 02 '22 13:11

Mahaveer


Installing the nrwl cli globally should do the trick, you'll need to enter the super user mode to do it.

sudo npm i -g @nrwl/cli

Alternative solutions can be found on the guide on the Nx Website here

https://nx.dev/l/a/tutorial/01-create-application

like image 23
superdwale Avatar answered Nov 02 '22 11:11

superdwale


Either you don't have refreshed your zsh paths, which can be fixed by opening a new terminal or type

rehash

in the prompt.

If this doesn't work then nx isn't globally installed on your machine. You have to type npm run nx [your command] instead of just "nx" to use it, so in your case:

npm run nx -- g @nrwl/angular:lib shared

Sources: https://nx.dev/latest/angular/cli/overview#installing-the-cli

like image 40
Ruapsin Avatar answered Nov 02 '22 13:11

Ruapsin


Do we really need to install @nrwl/cli ?

Just installing the nx resolve the issue for me

sudo npm install -g nx@latest
like image 37
San Jaisy Avatar answered Nov 02 '22 11:11

San Jaisy