Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create project in similar destination as another project due to projectName being affected by directory #16308

Closed
PowerSupply opened this issue Apr 14, 2023 · 6 comments

Comments

@PowerSupply
Copy link
Contributor

Current Behavior

Running the following generator...

import { Tree } from "@nrwl/devkit";
import { libraryGenerator, remote } from "@nrwl/angular/generators";

export default async function (tree: Tree) {
    const name = 'test'

    await libraryGenerator(tree, {
        name,
        directory: 'libs/xxx',
    });

    await remote(tree, {
        name,
        directory: 'apps/xxx'
    });
}

...gives errors...:

Skipping project found at apps/xxx/test since project xxx-test already exists at libs/xxx/test! Specify a unique name for the project to allow Nx to differentiate between the two projects.
Skipping project found at apps/xxx/test since project xxx-test already exists at libs/xxx/test! Specify a unique name for the project to allow Nx to differentiate between the two projects.

 >  NX   Cannot find apps/xxx/test/.eslintrc.json
 ...

This is caused by the libraryGenerator and the remote generator (and many others like the workspace move generator) changes the projectName in part based on the directory.

I know this is intended behaviour but it causes problems and I think it is inexplicit that the name is not the name you supply to the generator. After you generate/move a project, you have to guess the project name.

I propose that this behaviour is changed. To avoid a breaking change you could add an option to keep the legacy behaviour or introduce a migration to change the code.

Expected Behavior

The above generator works. Or introduce the changed behaviour I mentioned earlier.

GitHub Repo

No response

Steps to Reproduce

  1. Run a generator with the following code:
import { Tree } from "@nrwl/devkit";
import { libraryGenerator, remote } from "@nrwl/angular/generators";

export default async function (tree: Tree) {
    const name = 'test'

    await libraryGenerator(tree, {
        name,
        directory: 'libs/xxx',
    });

    await remote(tree, {
        name,
        directory: 'apps/xxx'
    });
}

Nx Report

Node : 18.13.0
   OS   : darwin arm64
   npm  : 8.19.3
   
   nx                      : 16.0.0-beta.0
   @nrwl/js                : 16.0.0-beta.0
   @nrwl/jest              : 16.0.0-beta.0
   @nrwl/linter            : 16.0.0-beta.0
@nrwl/workspace         : 16.0.0-beta.0
   @nrwl/angular           : 16.0.0-beta.0
   @nrwl/cypress           : 16.0.0-beta.0
   @nrwl/devkit            : 16.0.0-beta.0
   @nrwl/eslint-plugin-nx  : 16.0.0-beta.0
   @nrwl/nx-plugin         : 16.0.0-beta.0
   @nrwl/tao               : 16.0.0-beta.0
   @nrwl/vite              : 16.0.0-beta.0
   @nrwl/web               : 16.0.0-beta.0
   @nrwl/webpack           : 16.0.0-beta.0
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   @xxx/yyy : 8.0.1
   @twittwer/compodoc          : 1.5.3

Failure Logs

Skipping project found at apps/xxx/test since project xxx-test already exists at libs/xxx/test! Specify a unique name for the project to allow Nx to differentiate between the two projects.
Skipping project found at apps/xxx/test since project xxx-test already exists at libs/xxx/test! Specify a unique name for the project to allow Nx to differentiate between the two projects.

 >  NX   Cannot find apps/xxx/test/.eslintrc.json

Additional Information

No response

@PowerSupply
Copy link
Contributor Author

This is also a problem using Nx 15.8.7:

   Node : 18.13.0
   OS   : darwin arm64
   npm  : 8.19.3
   
   nx                      : 15.8.7
   @nrwl/js                : 15.8.7
   @nrwl/jest              : 15.8.7
   @nrwl/linter            : 15.8.7
   @nrwl/workspace         : 15.8.7
   @nrwl/angular           : 15.8.7
   @nrwl/cli               : 15.8.7
   @nrwl/cypress           : 15.8.7
   @nrwl/devkit            : 15.8.7
   @nrwl/eslint-plugin-nx  : 15.8.7
   @nrwl/nx-plugin         : 15.8.7
   @nrwl/tao               : 15.8.7
   @nrwl/vite              : 15.8.7
   @nrwl/webpack           : 15.8.7
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   @xxx/yyy: 8.0.1
   @twittwer/compodoc          : 1.5.3

Error: Project name already exists.
    at ProjectDefinitionCollection.add (/Users/paustr/Documents/Dev/gaia/packages/angular_devkit/core/src/workspace/definitions.ts:147:13)
    at /Users/paustr/packages/schematics/angular/application/index.ts:219:24
    at /Users/paustr/packages/schematics/angular/utility/workspace.ts:66:26
    at callRuleAsync (/Users/paustr/packages/angular_devkit/schematics/src/rules/call.ts:79:16)

 >  NX   Project name already exists.


Error: Project name already exists.
    at ProjectDefinitionCollection.add (/Users/paustr/Documents/Dev/gaia/packages/angular_devkit/core/src/workspace/definitions.ts:147:13)
    at /Users/paustr/packages/schematics/angular/application/index.ts:219:24
    at /Users/paustr/packages/schematics/angular/utility/workspace.ts:66:26
    at callRuleAsync (/Users/paustr/packages/angular_devkit/schematics/src/rules/call.ts:79:16)
MacBook-Pro:gaia paustr$ 

I don't know why the error is output twice.

@PowerSupply PowerSupply changed the title Unable to create project in similar destination as another project due to projectName being affected by destination Unable to create project in similar destination as another project due to projectName being affected by directory Apr 14, 2023
@PowerSupply
Copy link
Contributor Author

Any progress on this?

@antonyftp
Copy link

Hi ! I have pretty much the same error on my side but in .netcore. My issue is when I try to create another .net core app with the plugin @nx-dotnet/core, it gives me this error :

Skipping project found at apps/reportbackendapp since project reportbackendapp already exists at apps/reportbackendapp! Specify a unique name for the project to allow Nx to differentiate between the two projects.

The thing is this app doesn't exist before and my other app doesn't have the same name.

@PowerSupply
Copy link
Contributor Author

Any progress on this? My proposed solution would avoid the problem in #17430 as well.

Copy link

github-actions bot commented Dec 5, 2023

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants