nrwl / nx

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

Unable to run any command or even build the projectGraph if externalDependency is involved #28203

Open lucas-lowry-se opened 1 month ago

lucas-lowry-se commented 1 month ago

Current Behavior

In both existing and newly created workspaces, any target involving an external dependency gets the following error and kills the daemon:

Error: The externalDependency 'cypress' for 'simple-ng-cypress-e2e:e2e' could not be found.

That particular error appears as soon as I try to open the project graph for a brand new Angular workspace set to use cypress. In other workspaces, I've seen similar behavior for eslint and jest as soon as the configuration is set to use those external dependencies and not their associated plug ins.

These tools are available on my PATH and runnable in the terminal used to start nx.

Expected Behavior

These targets should run without issue.

GitHub Repo

No response

Steps to Reproduce

  1. Crete a new Angular workspace configured to use cypress
  2. Open the project graph in a web browser
  3. Open any of the targets in the project graph, the server dies with the error Error: The externalDependency 'cypress' for 'simple-ng-cypress-e2e:e2e' could not be found

Nx Report

Node           : 20.15.0
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.7.0

nx                 : 19.8.2
@nx/js             : 19.8.2
@nx/jest           : 19.8.2
@nx/linter         : 19.8.2
@nx/eslint         : 19.8.2
@nx/workspace      : 19.8.2
@nx/angular        : 19.8.2
@nx/cypress        : 19.8.2
@nx/devkit         : 19.8.2
@nx/eslint-plugin  : 19.8.2
@nrwl/tao          : 19.8.2
@nx/web            : 19.8.2
@nx/webpack        : 19.8.2
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/cypress/plugin
@nx/eslint/plugin

Failure Logs

/Users/lucaslowry/code/temp/test-nx-workspace/simple-ng-cypress/node_modules/nx/src/command-line/graph/graph.js:592
            plans[task.id] = planner.getPlans([task.id], individualTaskGraph)[task.id];
                                     ^

Error: The externalDependency 'cypress' for 'simple-ng-cypress-e2e:e2e' could not be found
    at createTaskGraphClientResponse (/Users/lucaslowry/code/temp/test-nx-workspace/simple-ng-cypress/node_modules/nx/src/command-line/graph/graph.js:592:38)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Server.<anonymous> (/Users/lucaslowry/code/temp/test-nx-workspace/simple-ng-cypress/node_modules/nx/src/command-line/graph/graph.js:353:36) {
  code: 'GenericFailure'
}

Package Manager Version

No response

Operating System

Additional Information

I'm also using Volta as my version manager. I am not using pnpm which appears to have caused issues like this in the past.

kumboleijo commented 1 month ago

I'm currently stumbling into the same issue. I'm trying to improve my linting tasks using externalDependencies like the docs propose (https://nx.dev/reference/inputs#external-dependencies). I'm having a pnpm monorepo using version 8.15.1.

❯ pnpm nx report

 NX   Report complete - copy this into the issue template

Node           : 20.17.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 8.15.1

nx             : 19.5.7
@nx/js         : 19.5.7
@nx/jest       : 19.5.7
@nx/linter     : 19.5.7
@nx/eslint     : 19.5.7
@nx/workspace  : 19.5.7
@nx/devkit     : 19.5.7
@nx/node       : 19.5.7
@nrwl/tao      : 19.5.7
typescript     : 5.5.2

When I put eslint (which is installed as devDependency in my package) under the externalDependencies (project.json) I get the following error:

Error: The externalDependency 'eslint' for '<MY_LINT_TASK>' could not be found

project.json

...
        "lint": {
            "inputs": [
                "sourceFiles",
                "{projectRoot}/.eslintrc",
                {
                    "externalDependencies": ["eslint"] # 🚨
                }
            ],
            "outputs": [],
            "cache": true
        },
...

package.json

...
    "dependencies": {
        ...
        "eslint": "8.57.0",
        ...
    },

Isn't that the way the externalDependencies are meant to work? Or am I missing something here?


Update

I just updated to nx@19.8.2 using pnpm nx migrate latest - the error is still happening.

getabetterpic commented 1 month ago

I'm seeing this same thing with jest when trying to use Atomizer to split specs using the Nx jest plugin.

$ nx test-ci settings
...
/Users/dansmith/src/looky/node_modules/nx/src/hasher/native-task-hasher-impl.js:32
        const plans = this.planner.getPlansReference(tasks.map((t) => t.id), taskGraph);
                                   ^

Error: The externalDependency 'jest' for 'settings:test-ci' could not be found
    at NativeTaskHasherImpl.hashTasks (/Users/dansmith/src/looky/node_modules/nx/src/hasher/native-task-hasher-impl.js:32:36)
    at InProcessTaskHasher.hashTasks (/Users/dansmith/src/looky/node_modules/nx/src/hasher/task-hasher.js:53:50)
    at handleHashTasks (/Users/dansmith/src/looky/node_modules/nx/src/daemon/server/handle-hash-tasks.js:30:56)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handleResult (/Users/dansmith/src/looky/node_modules/nx/src/daemon/server/server.js:107:16)
    at async handleMessage (/Users/dansmith/src/looky/node_modules/nx/src/daemon/server/server.js:81:9)
    at async /Users/dansmith/src/looky/node_modules/nx/src/daemon/server/server.js:45:9 {
  code: 'GenericFailure'
}

Relevant part of my nx.json:

"plugins": [
    {
      "plugin": "@nx/jest/plugin",
      "include": ["apps/**/*", "libs/**/*"],
      "options": {
        "targetName": "test",
        "ciTargetName": "test-ci"
      }
    }
  ]

I've removed the test target from my settings app's project.json, and nx test settings still works via inference as expected. However when trying to run nx test-ci settings I get the above error.

This is with Nx v18.3.5 and yarn.

itizarsa commented 1 month ago

It happens in all plugins when running inferred tasks. I have the nx20 repo bootstrapped with ts preset. I added @nx/eslint, when I run nx lint :app, it fails.

/Users/arshath/Dev/workflows/node_modules/nx/src/hasher/native-task-hasher-impl.js:32
        const plans = this.planner.getPlansReference(tasks.map((t) => t.id), taskGraph);
                                   ^

Error: The externalDependency 'eslint' for 'model:lint' could not be found
    at NativeTaskHasherImpl.hashTasks (/Users/arshath/Dev/workflows/node_modules/nx/src/hasher/native-task-hasher-impl.js:32:36)
    at InProcessTaskHasher.hashTasks (/Users/arshath/Dev/workflows/node_modules/nx/src/hasher/task-hasher.js:41:46)
    at handleHashTasks (/Users/arshath/Dev/workflows/node_modules/nx/src/daemon/server/handle-hash-tasks.js:30:56)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handleResult (/Users/arshath/Dev/workflows/node_modules/nx/src/daemon/server/server.js:172:16)
    at async handleMessage (/Users/arshath/Dev/workflows/node_modules/nx/src/daemon/server/server.js:110:9)
    at async /Users/arshath/Dev/workflows/node_modules/nx/src/daemon/server/server.js:72:9 {
  code: 'GenericFailure'
}

Node.js v20.16.0