Nx is not recognized as an internal or external command, operable program or batch file

Skip to content

Issue

I updated my NX Workspace to the latest version ("@nrwl/angular": "11.5.2") using it with Angular apps (v 11.2.6) in a monorepo.

I would like to generate a new Angular library using the following command:

ng generate @nrwl/angular:library --name=service --style=scss --directory=/libs/booking

But I receive the following error in the console:

SchematicsException [Error]: Project name "-libs-booking-service" is not valid. New project names must start with a letter, and must contain only alphanumeric characters or dashes. When adding a dash the segment after the dash must also start with a letter.

Somehow the command adds a dash - before the project name, generating the error.

I also wiped out the node_modules and reinstalled the packages again, but without any luck.


UPDATE

I leave below the steps that helped me to fix the issue after the hint from Shashank :

If I remove the leading / in the directory parameter, I get the following error:

ng generate @nrwl/angular:library --name=services --style=scss --directory=libs/booking TypeError: Cannot read property 'paths' of undefined

That it is due to the tsconfig.json that for NX should still be tsconfig.base.json. By renaming it (temporarily) the command works.

Solution

As per your comment, I think below command works for you.Your directory had /libs/booking, which should have been libs/booking

ng generate @nrwl/workspace:library --name=service --style=scss --directory=libs/booking

Answered By – Shashank Vivek

Answer Checked By – Timothy Miller (AngularFixing Admin)

Introduction 

With an operable program or batch file, this problem occurs when your path is missing something from the environment variable.

For this solution, you just need to follow a few important operations. 

Step 1

Go to the control panel and select the system and security options.

 

Step 2

When you click on the system and security option there open a new dialogue box. Then, you have to right-click on the system.

Nx is not recognized as an internal or external command, operable program or batch file
 

Step 3

When you click on the system it opens a dialogue box. Now you have to go to the advanced System setting and then click here.

 

Step 4

When you click on the advanced setting there is an open dialogue box. Now you have to go to the system property and click on the environment variables. 

 

Step 5

When you click on the environment variable there is an open dialogue box. Now you have seen that there is two variable that contains a system variable and user variable. Now you have to go to the user variable and click on the edit button and create your own user variable and put the pathname of this variable and then enter the path values which path you have to copy from your computer, C:\Program Files\nodejs\node_modules\npm\bin. Paste this path and click on the ok button.

 

Step 6

Now you have to go to the system variable and select the path which path you have add-in user variable, and then edit this path and then you have to select the edit button and then you have to add this copied path and then click ok button.

After completing this process, you have to run the ng version command and you can see that your system shows the CLI version using the command " ng -- version".

I hope you enjoy this article to learn more about Angular follow me c#chamangautam to learn about more technology follow C#corner.

How do you check NX is installed or not?

How to Determine NX Version, Sold To, and License in Use.
Open NX..
Open an existing . ... .
Click File (tab) –> Help –> About NX..
Click System Information..
An Information Window will appear..
Notice the NX Version:.

How do I use NX command line?

React Tutorial.
1 - Create Application..
2 - Add E2E Test..
3 - Display Todos..
4 - Connect to API..
5 - Add Node Application..
6 - Proxy Configuration..
7 - Share Code..
8 - Create Libraries..

What is NX in NPM?

Nx is a smart and extensible build framework to help you architect, test, and build at any scale — integrating seamlessly with modern technologies and frameworks while providing a distributed graph-based task execution, computation caching, smart rebuilds of affected projects, powerful code generators, editor support, ...

How do I run a NX workspace?

Install nx globally to invoke the command directly using nx , or use npx nx , yarn nx , or pnpx nx ..
Examples. Run the build target for the myapp : ... .
configuration (-c) A named builder configuration, defined in the "configurations" section of the workspace configuration file. ... .
help. Show help..
version. Show version number..