nrwl / nx

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

NestJS - Error: The externalDependency 'webpack-cli' for 'project:build' could not be found. #29116

Open Fafnur opened 5 days ago

Fafnur commented 5 days ago

Current Behavior

If you add yarn.lock to .gitignore for a monorepo with nestjs, the project will crash with an error.

Image

Error message:

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: /mnt/Storage/Development/angular/nx-gitignore-bug/.nx/workspace-data/d/daemon.log

If you remove yarn.lock from .gitignore, everything is fine.

Image

Expected Behavior

Adding yarn.lock should not affect server startup with yarn.

GitHub Repo

https://github.com/Fafnur/nx-gitignore-bug

Steps to Reproduce

  1. Generate a new workspace with nx Image
  2. Set yarn as default manager in package.json "packageManager": "yarn@4.5.3"
  3. Create .yarnrc.yml with content nodeLinker: node-modules
  4. Add yarn.lock in .gitignore

Nx Report

Node           : 22.11.0
OS             : linux-x64
Native Target  : x86_64-linux
yarn           : 4.5.3

nx                 : 20.1.4
@nx/js             : 20.1.4
@nx/jest           : 20.1.4
@nx/eslint         : 20.1.4
@nx/workspace      : 20.1.4
@nx/devkit         : 20.1.4
@nx/eslint-plugin  : 20.1.4
@nx/nest           : 20.1.4
@nx/node           : 20.1.4
@nx/web            : 20.1.4
@nx/webpack        : 20.1.4
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin

Failure Logs

/mnt/Storage/Development/angular/taro/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 'webpack-cli' for 'backend:build' could not be found
    at NativeTaskHasherImpl.hashTasks (/mnt/Storage/Development/angular/taro/node_modules/nx/src/hasher/native-task-hasher-impl.js:32:36)
    at InProcessTaskHasher.hashTasks (/mnt/Storage/Development/angular/taro/node_modules/nx/src/hasher/task-hasher.js:41:46)
    at handleHashTasks (/mnt/Storage/Development/angular/taro/node_modules/nx/src/daemon/server/handle-hash-tasks.js:30:56)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async handleResult (/mnt/Storage/Development/angular/taro/node_modules/nx/src/daemon/server/server.js:172:16)
    at async handleMessage (/mnt/Storage/Development/angular/taro/node_modules/nx/src/daemon/server/server.js:110:9)
    at async /mnt/Storage/Development/angular/taro/node_modules/nx/src/daemon/server/server.js:72:9 {
  code: 'GenericFailure'
}

Node.js v22.11.0

Package Manager Version

4.5.3

Operating System

Additional Information

No response

mataai commented 1 day ago

I have the same exact problem. Added package-lock.json to gitignore monorepo wouldn't start even after re-cloning the repo and fresh modules install. Removing package-lock.json from .gitignore instantly fixed it.

Node           : 20.11.1
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.5.0

nx (global)        : 20.1.4
nx                 : 20.1.4
@nx/js             : 20.1.4
@nx/jest           : 20.1.4
@nx/eslint         : 20.1.4
@nx/workspace      : 20.1.4
@nx/angular        : 20.1.4
@nx/devkit         : 20.1.4
@nx/eslint-plugin  : 20.1.4
@nx/nest           : 20.1.4
@nx/node           : 20.1.4
@nx/web            : 20.1.4
@nx/webpack        : 20.1.4
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
---------------------------------------
Community plugins:
angular-eslint : 18.4.3