nrwl / nx

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

Using `dependentTasksOutputFiles` results in the deamon crashing #20766

Open Nokel81 opened 10 months ago

Nokel81 commented 10 months ago

Current Behavior

Similar to https://github.com/nrwl/nx/issues/18080

When I run npm exec -- lerna watch --ignore lens-desktop -- npm run build:dev eventually I get the following message:

 >  Lerna (powered by Nx)   Daemon process terminated and closed the connection

   Please rerun the command, which will restart the daemon.
   If you get this error again, check for any errors in the daemon process logs found in: /Users/smalton/Documents/lens-desktop-monorepo/node_modules/.cache/nx/d/daemon.log

Expected Behavior

It complete the build successfully.

GitHub Repo

No response

Steps to Reproduce

  1. Have the following nx.json

    {
    "tasksRunnerOptions": {
    "default": {
      "runner": "nx/tasks-runners/default",
      "options": {
        "cacheableOperations": ["lint", "lint:fix", "build", "build:types"]
      }
    }
    },
    "namedInputs": {
    "productionFiles": [
      "default",
      "!{projectRoot}/**/*.test.ts",
      "!{projectRoot}/**/*.test.tsx",
      "!{projectRoot}/**/*.md"
    ],
    "deps": [{ "dependentTasksOutputFiles": "dist/**/*.d.ts", "transitive": true }]
    },
    "targetDefaults": {
    "build": {
      "dependsOn": [
        "^build"
      ],
    
      "inputs": [
        "productionFiles",
    
        {
          "env": "NODE_ENV"
        }
      ],
    
      "outputs": [
        "{projectRoot}/dist/index.js",
        "{projectRoot}/dist/index.css"
      ]
    },
    
    "build:types": {
      "dependsOn": [
        "^build:types"
      ],
    
      "inputs": [
        "productionFiles",
        "deps"
      ],
    
      "outputs": [
        "{projectRoot}/dist/index.d.ts",
        "{projectRoot}/dist/src"
      ]
    },
    "build:app": {
      "dependsOn": [
        "^build"
      ]
    },
    "linkable-push": {
      "dependsOn": [
        "build"
      ],
      "inputs": [],
      "outputs": []
    },
    "test:integration": {
      "dependsOn": [
        "^build"
      ]
    },
    "build:docs": {
      "dependsOn": [
        "^build:types"
      ]
    },
    "lint": {
      "dependsOn": [
        {
          "projects": "@lensapp/eslint-config-and-prettier",
          "target": "build"
        },
        "^build:types"
      ],
    
      "inputs": [
        "productionFiles"
      ]
    },
    "lint:fix": {
      "dependsOn": [
        {
          "projects": "@lensapp/eslint-config-and-prettier",
          "target": "build"
        },
        "^build:types"
      ],
    
      "inputs": [
        "productionFiles"
      ]
    },
    "test:unit": {
      "dependsOn": [
        "^build"
      ]
    }
    }
    }
  2. If I remove transitive: true, then the crash doesn't happen, but then my build:types doesn't get rebuilt if the outputs of a dependency change

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 18.18.2
   OS     : darwin-arm64
   npm    : 9.9.2

   nx          : 16.10.0
   lerna       : 7.4.2
   @nx/devkit  : 16.10.0
   @nrwl/tao   : 16.10.0
   typescript  : 4.9.5

Failure Logs

/Users/smalton/Documents/lens-desktop-monorepo/node_modules/nx/src/hasher/task-hasher.js:189
            result.push(...(await this.hashDepOuputs(task, dependentTasksOutputFiles, taskGraph, transitive)));
                   ^

RangeError: Maximum call stack size exceeded
    at TaskHasherImpl.hashDepsOutputs (/Users/smalton/Documents/lens-desktop-monorepo/node_modules/nx/src/hasher/task-hasher.js:189:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async TaskHasherImpl.hashSelfAndDepsInputs (/Users/smalton/Documents/lens-desktop-monorepo/node_modules/nx/src/hasher/task-hasher.js:141:25)
    at async /Users/smalton/Documents/lens-desktop-monorepo/node_modules/nx/src/hasher/task-hasher.js:114:35
    at async InProcessTaskHasher.hashTask (/Users/smalton/Documents/lens-desktop-monorepo/node_modules/nx/src/hasher/task-hasher.js:55:21)
    at async Promise.all (index 0)
    at async InProcessTaskHasher.hashTasks (/Users/smalton/Documents/lens-desktop-monorepo/node_modules/nx/src/hasher/task-hasher.js:52:16)
    at async handleHashTasks (/Users/smalton/Documents/lens-desktop-monorepo/node_modules/nx/src/daemon/server/handle-hash-tasks.js:22:37)
    at async handleResult (/Users/smalton/Documents/lens-desktop-monorepo/node_modules/nx/src/daemon/server/server.js:111:16)
    at async handleMessage (/Users/smalton/Documents/lens-desktop-monorepo/node_modules/nx/src/daemon/server/server.js:85:9)


### Package Manager Version

_No response_

### Operating System

- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)

### Additional Information

_No response_
jaysoo commented 10 months ago

@Nokel81 A repro would help to debug the issue, would you be able to share one?

Nokel81 commented 10 months ago

I can try. The only thing is that we have ~190 packages currently so that might be the issue

jaysoo commented 10 months ago

This one is a recursion issue, so I imagine it's possible on a small repo. If you cannot we can try to debug it, but i'll take longer.

Nokel81 commented 10 months ago

I will try to make a reproduction today.

Nokel81 commented 6 months ago

I just found another way that this crashes, having

"inputs": ["productionFiles", { "dependentTasksOutputFiles": ["dist/index.d.ts", "dist/src/**/*.d.ts"] }],

instead of

"inputs": ["productionFiles", { "dependentTasksOutputFiles": "dist/**/*.d.ts" }],

causes the same daemon crash issue