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

Cannot generate new angular app in existing nx workspace #15348

Closed
jerkovicl opened this issue Mar 1, 2023 · 18 comments · Fixed by #15503
Closed

Cannot generate new angular app in existing nx workspace #15348

jerkovicl opened this issue Mar 1, 2023 · 18 comments · Fixed by #15503
Assignees
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug

Comments

@jerkovicl
Copy link

Current Behavior

I have a working nx workspace with 1 angular app and multiple libs.
I am on latest angular v15.2 and nx v15.8.1
Tried generating a new angular app but got error.
image
`

Expected Behavior

Generating a new angular app inside existing nx workspace works

GitHub Repo

No response

Steps to Reproduce

  1. Run command nx g @nrwl/angular:application my-app inside existing nx workspace

Nx Report

nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.14.0
   OS   : win32 x64
   npm  : 9.3.1

   nx                      : 15.8.1
   @nrwl/js                : 15.8.1
   @nrwl/jest              : 15.8.1
   @nrwl/linter            : 15.8.1
   @nrwl/workspace         : 15.8.1
   @nrwl/angular           : 15.8.1
   @nrwl/cli               : 15.8.1
   @nrwl/cypress           : 15.8.1
   @nrwl/devkit            : 15.8.1
   @nrwl/eslint-plugin-nx  : 15.8.1
   @nrwl/nx-plugin         : 15.8.1
   @nrwl/rollup            : 15.8.1
   @nrwl/storybook         : 15.8.1
   @nrwl/tao               : 15.8.1
   @nrwl/web               : 15.8.1
   @nrwl/webpack           : 15.8.1
   @nrwl/nx-cloud          : 15.1.1
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   ngx-build-plus     : 15.0.0
   @compodoc/compodoc : 1.1.19
   @storybook/angular : 6.5.16
   ---------------------------------------
   Local workspace plugins:
         @fiyu/lib-toolkit

Failure Logs

nx g @nrwl/angular:application cool-app --dry-run --verbose

>  NX  Generating @nrwl/angular:application

√ Would you like to configure routing for this application? (y/N) · false
√ Would you like to use Standalone Components? (y/N) · false

 >  NX   Cannot find configuration for 'cool-app'


Error: Cannot find configuration for 'cool-app'
    at readProjectConfiguration (C:\Git\projects\fiyu\frontend\node_modules\nx\src\generators\utils\project-configuration.js:88:15)
    at updateAppAndE2EProjectConfigurations (C:\Git\projects\fiyu\frontend\node_modules\@nrwl\angular\src\generators\application\lib\update-config-files.js:29:57)
    at updateConfigFiles (C:\Git\projects\fiyu\frontend\node_modules\@nrwl\angular\src\generators\application\lib\update-config-files.js:12:5)
    at C:\Git\projects\fiyu\frontend\node_modules\@nrwl\angular\src\generators\application\application.js:56:37
    at Generator.next (<anonymous>)
    at fulfilled (C:\Git\projects\fiyu\frontend\node_modules\tslib\tslib.js:164:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Additional Information

No response

@FrozenPandaz FrozenPandaz added the scope: angular Issues related to Angular support in Nx label Mar 1, 2023
@hackmajoris
Copy link

hackmajoris commented Mar 1, 2023

I have the same issue.
Nx version: 15.8.1

At the: 'nx@15.8.1/node_modules/nx/src/generators/utils/project-configuration.js' it looks for 'angular.json' file which was removed when the migrations were run.

function readProjectConfiguration(tree, projectName) {
    const allProjects = readAndCombineAllProjectConfigurations(tree);
    if (!allProjects[projectName]) {
        // temporary polyfill to make sure our generators work for existing angularcli workspaces
        if (tree.exists('angular.json')) {
            const angularJson = toNewFormat((0, json_1.readJson)(tree, 'angular.json'));
            if (angularJson.projects[projectName])
                return angularJson.projects[projectName];
        }
        throw new Error(`Cannot find configuration for '${projectName}'`);
    }
    return allProjects[projectName];
}

@jerkovicl
Copy link
Author

jerkovicl commented Mar 1, 2023

@hackmajoris yeah I am missing angular.json as well after migrations removed it

@leosvelperez
Copy link
Member

Thanks for reporting this!

I couldn't reproduce the issue in a freshly generated 15.8.1 repo on Windows. Could you provide a repo where the issue can be reproduced so we can troubleshoot it?

@hackmajoris
Copy link

Thanks for reporting this!

I couldn't reproduce the issue in a freshly generated 15.8.1 repo on Windows. Could you provide a repo where the issue can be reproduced so we can troubleshoot it?

@jerkovicl will you?

@jerkovicl
Copy link
Author

@hackmajoris cant do it before Monday, if you can do it before, it would be great.

@hackmajoris
Copy link

hackmajoris commented Mar 4, 2023

@jerkovicl @leosvelperez fixed it. Here is how: I use PNPM as a package manager. I had a file 'pnpm-workspace.yml' from the beginning and it worked well with older Nx versions. With the latest upgrade, the angular.json file was split and removed and it started to give that missing configuration error. After removing pnpm-workspace.yml file it worked. I assume it tries different configuration(the one with angular.json) when you have that file.

@leosvelperez you should be able to reproduce the issue with PNPM and pnpm-worspace.yml file.

@jerkovicl
Copy link
Author

@hackmajoris i am using npm as package manager

@hackmajoris
Copy link

hackmajoris commented Mar 4, 2023

@hackmajoris i am using npm as package manager

Do you have a 'workspaces' attribute on your package.json file?

@jerkovicl
Copy link
Author

jerkovicl commented Mar 5, 2023

@hackmajoris i am using npm as package manager

Do you have a 'workspaces' attribute on your package.json file?

Nope, only nx attribute:

"nx": {
    "tags": [
      "type:app"
    ]
},

@jerkovicl
Copy link
Author

@leosvelperez i sent you a repo on dm in slack community so you can reproduce issue

@aleix10kst
Copy link

@jerkovicl I've had the same issue when trying to create a library. I've removed the nx property from my root package.json file, and it has worked well. Not sure what was the issue, but I think it has to do with how Nx creates a "base" project when you define an nx property in the root package.json file.

@leosvelperez
Copy link
Member

@jerkovicl thanks for the repro! I'll try to set some time later this week to look at this. In the meantime, as mentioned by @aleix10kst, removing the nx property in the root package.json would fix your workspace. If your root is not an Nx project, you shouldn't have that property set there. If you need the root dir to be considered an Nx project (and have the rest of the projects as nested projects), you can consider creating a project.json file at the root instead.

@jerkovicl
Copy link
Author

@aleix10kst @leosvelperez yep removing nx property fixed it for me, thx for help🍾

Should I close this or leave it open?

@leosvelperez
Copy link
Member

Thanks for confirming it worked for you! Yeah, I'm closing the issue since it seems to have been caused by a wrong setup.

Anyways, I'll spend later some time on it. A nested setup with the nx property in the package.json should still work, though that was not what you needed or were trying to achieve.

@aleix10kst
Copy link

@leosvelperez but based on this guide, you can have the property there to run root-level scripts (which was my case) and it should work. Am I missing something?

@leosvelperez
Copy link
Member

@aleix10kst you're correct. That's what I said I'll take a look later. I closed this because the OP wasn't using that and their issue was solved. I'll reopen it to track what you mention.

@leosvelperez leosvelperez reopened this Mar 7, 2023
@jerkovicl
Copy link
Author

@leosvelperez but based on this guide, you can have the property there to run root-level scripts (which was my case) and it should work. Am I missing something?

Yeah if i remember correctly i added nx prop because of that feature when i saw it in release blog post but never used it so far

@github-actions
Copy link

github-actions bot commented Apr 8, 2023

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 Apr 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
5 participants