5

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.

2
  • Can you try ng generate @nrwl/workspace:library --name=service --style=scss --directory=libs/booking Commented Mar 23, 2021 at 15:19
  • There was a combination of leading slash and the tsconfig file name. If you write an answer I will accept it. Commented Mar 23, 2021 at 15:47

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

Generate an application

Run ng g @nrwl/angular:app my-app to generate an application.

When using Nx, you can create multiple applications and libraries in the same workspace.

Generate a component

npx nx generate @nrwl/angular:component my-component --project=your-app --module=/apps/your-app/src/app --no-interactive

Run npx nx generate @nrwl/angular:component my-component --project=your-app --module=/apps/your-app/src/app --no-interactive to generate a new component.

Generate a library

Run ng g @nrwl/angular:lib my-lib to generate a library.

Build

Run nx build your-app to build the project. The build artifacts will be stored in the dist/ directory.

Running unit tests

Run ng test your-app to execute the unit tests via Jest.

Run nx affected:test --codeCoverage --skip-nx-cache to execute the unit tests affected by a change.

Understand your workspace

Run nx graph to see a diagram of the dependencies of your projects.

For existing projects with all '@nrwl' packages make sure you download npx if you haven't already.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.