nx-dotnet / nx-dotnet

A Nx plugin adding support for .NET 5+ (or .net core) projects, featuring full project graph and generator support.
https://www.nx-dotnet.com/
MIT License
262 stars 63 forks source link

[BUG] Migrating to NX v20 breaks depedencies #911

Open EelcoLos opened 2 weeks ago

EelcoLos commented 2 weeks ago

Current Behavior

Migrating to NX v20, then running npm i after installation is breaking the

Expected Behavior

@nx-dotnet/core runs with nx v20

Github Repo

https://github.com/EelcoLos/nx-tinkering/tree/error/nx-dotnet-v20-migration

Steps to Reproduce

  1. run npx nx migrate latest
  2. run npm i
  3. run npx nx migrate --run-migrations
  4. run npm i
  5. error shows

Nx Report

Can't generate due to the error

nx.json

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "defaultBase": "main",
  "namedInputs": {
    "default": [
      "{projectRoot}/**/*",
      "sharedGlobals"
    ],
    "production": [
      "default",
      "!{projectRoot}/.eslintrc.json",
      "!{projectRoot}/eslint.config.js",
      "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
      "!{projectRoot}/tsconfig.spec.json",
      "!{projectRoot}/jest.config.[jt]s",
      "!{projectRoot}/src/test-setup.[jt]s",
      "!{projectRoot}/test-setup.[jt]s"
    ],
    "sharedGlobals": []
  },
  "targetDefaults": {
    "@angular-devkit/build-angular:application": {
      "cache": true,
      "dependsOn": [
        "^build"
      ],
      "inputs": [
        "production",
        "^production"
      ]
    },
    "@nx/eslint:lint": {
      "cache": true,
      "inputs": [
        "default",
        "{workspaceRoot}/.eslintrc.json",
        "{workspaceRoot}/.eslintignore",
        "{workspaceRoot}/eslint.config.js"
      ]
    },
    "@nx/jest:jest": {
      "cache": true,
      "inputs": [
        "default",
        "^production",
        "{workspaceRoot}/jest.preset.js"
      ],
      "options": {
        "passWithNoTests": true
      },
      "configurations": {
        "ci": {
          "ci": true,
          "codeCoverage": true
        }
      }
    },
    "e2e-ci--**/*": {
      "dependsOn": [
        "^build"
      ]
    },
    "@nx/js:tsc": {
      "cache": true,
      "dependsOn": [
        "^build"
      ],
      "inputs": [
        "production",
        "^production"
      ]
    }
  },
  "plugins": [
    {
      "plugin": "@nx/playwright/plugin",
      "options": {
        "targetName": "e2e"
      }
    },
    {
      "plugin": "@nx/eslint/plugin",
      "options": {
        "targetName": "lint"
      }
    },
    {
      "plugin": "@nx-dotnet/core",
      "options": {
        "solutionFile": "nx-tinker.sln",
        "inferProjects": true,
        "nugetPackages": {},
        "inferredTargets": {
          "build": {
            "inputs": [
              "!{workspaceRoot}/package-lock.json",
              "!{workspaceRoot}/package.json",
              "!{workspaceRoot}/**/packag*.*",
              "!{workspaceRoot}/packag*.*",
              "!{workspaceRoot}/nx.json",
              "production",
              "^production"
            ],
            "targetName": "build",
            "configurations": {
              "production": {
                "runtime": "linux-x64",
                "configuration": "Release",
                "noDependencies": false
              }
            }
          },
          "lint": {
            "cache": true,
            "targetName": "lint"
          },
          "serve": "serve",
          "test": {
            "inputs": [
              "!{workspaceRoot}/package-lock.json",
              "!{workspaceRoot}/package.json",
              "!{workspaceRoot}/**/packag*.*",
              "!{workspaceRoot}/packag*.*",
              "!{workspaceRoot}/nx.json",
              "default",
              "^production"
            ],
            "targetName": "test",
            "cache": true,
            "configurations": {
              "ci": {
                "blame": false,
                "blameCrash": false,
                "logger": "trx"
              }
            }
          }
        },
        "ignorePaths": [],
        "tags": [
          "nx-dotnet"
        ]
      }
    }
  ],
  "generators": {
    "@nx/angular:application": {
      "e2eTestRunner": "playwright",
      "linter": "eslint",
      "style": "scss",
      "unitTestRunner": "jest"
    }
  },
  "pluginsConfig": {
    "@nx/js": {
      "projectsAffectedByDependencyUpdates": "auto"
    }
  },
  "nxCloudAccessToken": "<NX_CLOUD_ACCESS_TOKEN>"
}

Failure Logs

npm error ERESOLVE could not resolve
npm error
npm error While resolving: @nx-dotnet/core@2.4.5
npm error Found: nx@20.0.0
npm error node_modules/nx
npm error   dev nx@"20.0.0" from the root project
npm error   peer nx@">= 17 <= 20" from @nx/devkit@19.5.3
npm error   node_modules/@nx-dotnet/core/node_modules/@nx/devkit
npm error     @nx/devkit@"19.5.3" from @nx-dotnet/core@2.4.5
npm error     node_modules/@nx-dotnet/core
npm error       dev @nx-dotnet/core@"2.4.5" from the root project
npm error     @nx/devkit@"19.5.3" from @nrwl/devkit@19.5.3
npm error     node_modules/@nx-dotnet/core/node_modules/@nrwl/devkit
npm error       @nrwl/devkit@"19.5.3" from @nx/devkit@19.5.3
npm error   3 more (@nx/devkit, @nx/devkit, @nx/workspace)
npm error
npm error Could not resolve dependency:
npm error peer nx@">=18.0.0 <20.0.0" from @nx-dotnet/core@2.4.5
npm error node_modules/@nx-dotnet/core
npm error   dev @nx-dotnet/core@"2.4.5" from the root project
npm error
npm error node_modules/@nx-dotnet/core
npm error   dev @nx-dotnet/core@"2.4.5" from the root project
npm error node_modules/@nx-dotnet/core
npm error node_modules/@nx-dotnet/core
npm error   dev @nx-dotnet/core@"2.4.5" from the root project
npm error
npm error Conflicting peer dependency: nx@19.8.4
npm error node_modules/nx
npm error   peer nx@">=18.0.0 <20.0.0" from @nx-dotnet/core@2.4.5
npm error   node_modules/@nx-dotnet/core
npm error     dev @nx-dotnet/core@"2.4.5" from the root project
npm error node_modules/@nx-dotnet/core
npm error   dev @nx-dotnet/core@"2.4.5" from the root project
npm error
npm error Conflicting peer dependency: nx@19.8.4
npm error node_modules/nx
npm error   peer nx@">=18.0.0 <20.0.0" from @nx-dotnet/core@2.4.5
npm error node_modules/@nx-dotnet/core
npm error   dev @nx-dotnet/core@"2.4.5" from the root project
npm error
npm error Conflicting peer dependency: nx@19.8.4
npm error node_modules/@nx-dotnet/core
npm error   dev @nx-dotnet/core@"2.4.5" from the root project
npm error
npm error node_modules/@nx-dotnet/core
npm error node_modules/@nx-dotnet/core
npm error node_modules/@nx-dotnet/core
npm error   dev @nx-dotnet/core@"2.4.5" from the root project
npm error
npm error Conflicting peer dependency: nx@19.8.4
npm error node_modules/nx
npm error   peer nx@">=18.0.0 <20.0.0" from @nx-dotnet/core@2.4.5
npm error   node_modules/@nx-dotnet/core
npm error     dev @nx-dotnet/core@"2.4.5" from the root project

Additional Information

No response

EelcoLos commented 3 days ago

FYI for ppl following this: I tried debugging this myself. It seems harder to work on this as a beginner on this repo than I thought. My thoughts so far:

  1. CONTRIBUTING.md starting guide isn't complete.

    Validating plug-in changes locally

    The recommended way to validate your changes is to deploy the plugin locally to a fresh nx workspace.

    * A sandbox workspace can be generated via `yarn sandbox`
    * This script will build/publish the plugin to a sandbox workspace (./tmp/sandbox)
    * Verdaccio is leveraged to start a locally running instance of npm (http://localhost:4872/)
        The server will close when the script is stopped
    * use `nx generate @nx-dotnet/core:[generator]` to validate your changes manually

    yarn sandbox references files that do not exist: https://github.com/EelcoLos/nx-dotnet/blob/6dc1e995be359f372da506c65e1e20ccd6682ca3/tools/scripts/sandbox.ts#L11C1-L12C1

and publish-all https://github.com/EelcoLos/nx-dotnet/blob/6dc1e995be359f372da506c65e1e20ccd6682ca3/tools/scripts/sandbox.ts#L24C6-L24C7 , which was removed in https://github.com/nx-dotnet/nx-dotnet/pull/874 (file itself: https://github.com/nx-dotnet/nx-dotnet/blob/5f0dd3a49717e12a7fe788c729c4a35c4bb7adc9/tools/scripts/publish-all/index.ts)

  1. Most importantly: This plugin references NXPluginV1, whereas v20 demands NXPluginV2 on various files. This migration will have some work in here, but is doable i guess.
  2. I almost got it to work, then the final test of the sandbox tries to test to a create-nx-workspace with preset empty. This preset doesn't exist any more. Also, when trying to execute this, I get a Failed to create nx workspace error, without being able to dive deeper.

Hope this'll at least inform you. My question is: should I log these as seperate issues? And if so, as it's needed for this package to move forward, still be part of the same work?

EelcoLos commented 2 days ago

As pointed out by @AgentEnder on https://github.com/nx-dotnet/nx-dotnet/discussions/851#discussioncomment-10003811 , he's working on a total redesign of the plugin. Hopefully it'll be here soon.