nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.61k stars 2.36k forks source link

"Project name already exists" error when generating Angular library with the same name as an existing app #8261

Closed markosankovic closed 2 years ago

markosankovic commented 2 years ago

Current Behavior

"Error: Project name already exists." is reported by the nx generator (Angular) when trying to generate a library with the same name as an existing app. The recommended directory structure is to use the same name for both app and lib, see: https://nx.dev/l/a/guides/monorepo-nx-enterprise#scope-where-a-library-lives-who-owns-it (happynrwlapp).

Expected Behavior

The nx generator should let me create library with the same name as an existing app. Not sure if this is possible since the error comes from the Angular schematics.

Steps to Reproduce

create-nx-workspace --preset=angular --name=acme --appName=detonator --style=css --nx-cloud=false
cd acme
nx generate @nrwl/angular:library --name=detonator

Failure Logs

Error: Project name already exists.
    at ProjectDefinitionCollection.add (/home/marko/tmp/acme/node_modules/@angular-devkit/core/src/workspace/definitions.js:88:19)
    at /home/marko/tmp/acme/node_modules/@schematics/angular/library/index.js:67:28
    at /home/marko/tmp/acme/node_modules/@schematics/angular/utility/workspace.js:40:34
Project name already exists.

Environment

  Node : 17.2.0
  OS   : linux x64
  npm  : 8.1.4

  nx : 13.3.9
  @nrwl/angular : 13.3.9
  @nrwl/cli : 13.3.9
  @nrwl/cypress : 13.3.9
  @nrwl/devkit : 13.3.9
  @nrwl/eslint-plugin-nx : 13.3.9
  @nrwl/express : undefined
  @nrwl/jest : 13.3.9
  @nrwl/linter : 13.3.9
  @nrwl/nest : undefined
  @nrwl/next : undefined
  @nrwl/node : undefined
  @nrwl/nx-cloud : undefined
  @nrwl/react : undefined
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.3.9
  @nrwl/web : undefined
  @nrwl/workspace : 13.3.9
  @nrwl/storybook : 13.3.9
  @nrwl/gatsby : undefined
  typescript : 4.4.4
  rxjs : 7.4.0
  ---------------------------------------
  Community plugins:
     @angular/animations: 13.1.1
     @angular/common: 13.1.1
     @angular/compiler: 13.1.1
     @angular/core: 13.1.1
     @angular/forms: 13.1.1
     @angular/platform-browser: 13.1.1
     @angular/platform-browser-dynamic: 13.1.1
     @angular/router: 13.1.1
     @angular-devkit/build-angular: 13.1.2
     @angular/cli: 13.1.2
     @angular/compiler-cli: 13.1.1
     @angular/language-service: 13.1.1
philipjfulcher commented 2 years ago

@markosankovic - Project names must be unique across apps and libs. In the example in the documentation page you linked, there's no library that actually has the same name as the application. There are several libs that are grouped under a directory that has the same name of the application, though. We refer to that directory as a grouping directory.

In your reproduction code, you'd do something like this to replicate the example in the documentation:

create-nx-workspace --preset=angular --name=acme --appName=detonator --style=css --nx-cloud=false
cd acme
nx generate @nrwl/angular:library --name=detonator/feature-main

This will create your app named detonator and then create a lib called detonator-feature-main. It will be created in the libs/detonator/feature-main directory.

Hopefully that clarifies things. If you have any more feedback, let us know what changes we could make to the docs to make this clearer.

markosankovic commented 2 years ago

@philipjfulcher thanks for the explanation. I'll just create a feature library in the grouping directory named same as the app, just as you suggested. My mistake, sorry.

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.