sverweij / dependency-cruiser

Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
https://npmjs.com/dependency-cruiser
MIT License
5.15k stars 249 forks source link

Issue: failure to run with combinedDependencies: true on a monorepo #947

Open asfaltboy opened 2 months ago

asfaltboy commented 2 months ago

Expected Behavior

I'm using yarn workspaces, and I expect it to work out of the box

Current Behavior

whenever I turn on the combinedDependencies: true option, I get an error

ERROR: Extracting dependencies ran afoul of...

pWorkspace.endsWith is not a function
... in e2e/playwright.config.ts

Without the option it runs ok, but reports packages as missing, where they are specified at the top level workspace package.json file

Possible Solution

I would love to see a more descriptive error, and ideally it would just work...

Steps to Reproduce (for bugs)

  1. Create a yarn workspaces project
  2. Add number of packages in different locations
  3. Run depcruise --init wizard, choose the defaults
  4. Set the option combinedDependencies: true
  5. Run depcruise .

Context

Just trying dependency-cruiser out, as an alternative to circular dependency lint rule of eslint-plugin-import (see rule definition of import/no-cycle)

I would also accept a workaround that disables the missing dependency check, if circular deps can be checked independently.

Your Environment

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

sverweij commented 3 weeks ago

IRL I've seen this happen when dependency-cruiser is run not in the root of the monorepo but instead in one of its sub folders (workaround then typically: run from the root).

Labeled as bug because dependency-cruiser either (1) needs to behave or (2) explain what's going on.

sverweij commented 1 week ago

Looking at the error message again it seems that the yarn workspaces in use in the project at hand has an unexpected non-string entry in the workspaces array (for yarn 2 and up workspaces is always supposed to be an array of strings, same with npm workspaces f.t.m.). I've adapted the code to deal with that (see #955).

The generic issue mentioned in my previous comment still exists, but seems unrelated to the current issue.

sverweij commented 1 week ago

The fix mentioned above has shipped with dependency-cruiser@16.4.1 (release notes: v16.4.1)