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

[BUG] Generating webapi does not seem to work in new nx workspace #838

Open
rudfoss opened this issue Mar 7, 2024 · 6 comments
Open

[BUG] Generating webapi does not seem to work in new nx workspace #838

rudfoss opened this issue Mar 7, 2024 · 6 comments
Assignees
Labels
bug Something isn't working scope: core

Comments

@rudfoss
Copy link

rudfoss commented Mar 7, 2024

Current Behavior

Running the base generator for an application fails with error: Cannot find configuration for '[app-name]-[app-name]' (app name is repeated when parameter --directory is specified)

Expected Behavior

Generator should generate webapi as expected.

Github Repo

No response

Steps to Reproduce

  1. Create new nx-repo
pnpm create create-nx-workspace@latest dotnet-test --workspaceType=integrated --nxCloud=skip --preset=apps --defaultBase=main
  1. Install @nx-dotnet/core and initialize
pnpm add -D @nx-dotnet/core
pnpm exec nx g @nx-dotnet/core:init
  1. Run generator to create a webapi in c#
pnpm exec nx generate @nx-dotnet/core:application --name=admin-api --language=C# --directory=admin/api --template=webapi --testTemplate=xunit --pathScheme=nx --verbose=true
# or without --directory
pnpm exec nx generate @nx-dotnet/core:application --name=admin-api --language=C# --template=webapi --testTemplate=xunit --pathScheme=nx --verbose=true

Generator fails with Cannot find configuration for [app-name]:

 NX  Generating @nx-dotnet/core:application

Executing Command: dotnet "new" "webapi" "--language" "C#" "--name" "DotnetTest.Admin.Api.AdminApi" "--output" "admin/api/admin-api"
The template "ASP.NET Core Web API" was created successfully.

Processing post-creation actions...
Restoring C:\projects\temp\dotnet-test\admin\api\admin-api\DotnetTest.Admin.Api.AdminApi.csproj:
  Determining projects to restore...
  All projects are up-to-date for restore.
Restore succeeded.


Executing Command: dotnet "new" "xunit" "--language" "C#" "--name" "DotnetTest.Admin.Api.AdminApi.Test" "--output" "admin/api/admin-api-test"
The template "xUnit Test Project" was created successfully.

Processing post-creation actions...
Restoring C:\projects\temp\dotnet-test\admin\api\admin-api-test\DotnetTest.Admin.Api.AdminApi.Test.csproj:
  Determining projects to restore...
  All projects are up-to-date for restore.
Restore succeeded.


Executing Command: dotnet "add" "admin/api/admin-api-test/DotnetTest.Admin.Api.AdminApi.Test.csproj" "reference" "admin/api/admin-api/DotnetTest.Admin.Api.AdminApi.csproj"
Reference `..\admin-api\DotnetTest.Admin.Api.AdminApi.csproj` added to the project.

 NX   Cannot find configuration for 'admin-api-admin-api'


Error: Cannot find configuration for 'admin-api-admin-api'
    at readProjectConfiguration (C:\projects\temp\dotnet-test\node_modules\.pnpm\nx@18.0.7\node_modules\nx\src\generators\utils\project-configuration.js:99:15)
    at C:\projects\temp\dotnet-test\node_modules\.pnpm\@nx-dotnet+core@2.2.0_@nx+js@18.0.7_nx@18.0.7\node_modules\@nx-dotnet\core\src\generators\add-swagger-target\add-swagger-target.js:11:63
    at Generator.next (<anonymous>)
    at C:\projects\temp\dotnet-test\node_modules\.pnpm\tslib@2.6.2\node_modules\tslib\tslib.js:169:75
    at new Promise (<anonymous>)
    at Object.__awaiter (C:\projects\temp\dotnet-test\node_modules\.pnpm\tslib@2.6.2\node_modules\tslib\tslib.js:165:16)
    at generateSwaggerSetup (C:\projects\temp\dotnet-test\node_modules\.pnpm\@nx-dotnet+core@2.2.0_@nx+js@18.0.7_nx@18.0.7\node_modules\@nx-dotnet\core\src\generators\add-swagger-target\add-swagger-target.js:9:20)
    at C:\projects\temp\dotnet-test\node_modules\.pnpm\@nx-dotnet+core@2.2.0_@nx+js@18.0.7_nx@18.0.7\node_modules\@nx-dotnet\core\src\generators\utils\generate-project.js:129:63
    at Generator.next (<anonymous>)
    at fulfilled (C:\projects\temp\dotnet-test\node_modules\.pnpm\tslib@2.6.2\node_modules\tslib\tslib.js:166:62)

Nx Report

NX   Report complete - copy this into the issue template

Node   : 20.9.0
OS     : win32-x64
pnpm   : 8.15.4

nx             : 18.0.7
@nx/js         : 18.0.7
@nx/workspace  : 18.0.7
@nx/devkit     : 17.0.2
@nrwl/tao      : 18.0.7
typescript     : 5.4.2
---------------------------------------
Community plugins:
@nx-dotnet/core : 2.2.0
---------------------------------------
The following packages should match the installed version of nx
  - @nx/devkit@17.0.2
  - @nrwl/devkit@17.0.2

To fix this, run `nx migrate nx@18.0.7`

nx.json

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "namedInputs": {
    "default": [
      "{projectRoot}/**/*",
      "sharedGlobals"
    ],
    "production": [
      "default"
    ],
    "sharedGlobals": []
  },
  "plugins": [
    "@nx-dotnet/core"
  ]
}

Failure Logs

No response

Additional Information

dotnet --version
8.0.102

pnpm -v
8.15.4

node -v
v20.9.0
@rudfoss rudfoss added bug Something isn't working needs-triage This issue has yet to be looked over by a core team member labels Mar 7, 2024
@rudfoss
Copy link
Author

rudfoss commented Mar 7, 2024

Current workaround.

  1. Run the generator once until it fails.
  2. Create project.json files for the app and test projects.
{
	"name": "admin-api",
	"$schema": "../../node_modules/nx/schemas/project-schema.json",
	"sourceRoot": "apps/admin-api",
	"projectType": "application",
	"targets": {},
	"tags": []
}
  1. Delete all files and folders except the project.json files from each folder.
  2. Re-run the generator. It succeeds since the project now exists in the nx graph.

@maxnatamo
Copy link

I'm also having the same issue, but I can't replicate the solution from @rudfoss.

@mhdubose
Copy link

mhdubose commented Mar 28, 2024

This is a duplicate of #828

EDIT: Despite having similar outcomes, it's not in fact a duplicate. The other issue is around the dryrun flag. This issue is related to not creating the project.json file when Nx Crystal is enabled for App projects, but webapi projects attempt to create a swagger project which is expecting the project.json file

@mhdubose
Copy link

mhdubose commented Mar 28, 2024

To be more explicit here, this line https://vscode.dev/github/nx-dotnet/nx-dotnet/blob/master/packages/core/src/generators/add-swagger-target/add-swagger-target.ts#L29 is attempting to retrieve the project configuration using this function from the core nx project https://vscode.dev/github/nrwl/nx/blob/master/packages/nx/src/generators/utils/project-configuration.ts#L187 which explicitly uses file patterns to look for the project.json file.

The project.json file is not being created, however, by default in nx 18+ https://vscode.dev/github/nx-dotnet/nx-dotnet/blob/master/packages/core/src/generators/utils/generate-project.ts#L192

@AgentEnder
Copy link
Member

Hi, yea this should be fixed. I'll try to make some time this week to get something put together.

@AgentEnder AgentEnder added scope: core and removed needs-triage This issue has yet to be looked over by a core team member labels Apr 1, 2024
@AgentEnder AgentEnder self-assigned this Apr 1, 2024
@rudfoss
Copy link
Author

rudfoss commented Apr 1, 2024

Thanks for the updates and the quick fix guys! It is greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working scope: core
Projects
None yet
Development

No branches or pull requests

4 participants