Dependency-cruiser: Not working on TypeScript classes

Created on 14 Apr 2019  ยท  4Comments  ยท  Source: sverweij/dependency-cruiser

Tried to use the tool without much success

image

It shows that little despite AppManager having dozens of imports

image

For reference the command I'm using is

depcruise --max-depth 99 --output-type dot .\src\scripts\main.ts | dot -T svg > dependencygraph.svg

When I try to use it on the all folder the result is empty, meaning when I run:

depcruise --max-depth 99 --output-type dot src/scripts | dot -T svg > dependencygraph.svg

Expected Behavior

It should show dependencies

Current Behavior

It doesn't show dependencies

Most helpful comment

  • If you've installed dependency-cruiser globally typescript needs to be installed globally as well in order for dependency-cruiser to find it. Judging from the command line script in your issue, you're using that.
  • If you run dependency-cruiser from a local install (so it's in your projects' node_modules and the binary is in ./node_nodules/.bin/depcruise) and typescript is installed locally, dependency-cruiser picks up that one.

Note that if you use depcruise on the command line you're using the globally installed one. So even if you install dependency-cruiser locally, it'll use the global one, and pick up any global compiler.

So you can do one of two things:

  • install typescript globally as well if you use the global depcruise
  • make sure to run the local depcruise script - either by calling call ./node_modules/.bin/depcruise directly (it's where the _scripts_ section of your package.json will look) or use npm's npx : npx depcruise ...

HTH

All 4 comments

From the diagram it seems the AppManager module cannot be found. This can have several causes. Assuming that AppManager exists, and the import reference in src/scripts/main is correct it might be dependency-cruiser can't find the typescript compiler (it searches for it in the same spot it's installed) - your second sample suggests this to be the case.

To know for sure: what does depcruise --info tell in your installation? If dependency-cruiser _could_ find the typescript compiler it'll look something like this (mark the โœ” in front of typescript and the extensions associated with typescript):

  Supported:

    If you need a supported, but not enabled transpiler ('โœ–' below), just install
    it in the same folder dependency-cruiser is installed. E.g. 'npm i livescript'
    will enable livescript support if it's installed in your project folder.

  Transpilers:

    โœ” javascript (>es1)
    โœ– coffee-script (>=1.0.0 <2.0.0)
    โœ– coffeescript (>=1.0.0 <3.0.0)
    โœ– livescript (>=1.0.0 <2.0.0)
    โœ” typescript (>=2.0.0 <4.0.0)

  Extensions:

    โœ” .js
    โœ” .mjs
    โœ” .jsx
    โœ” .vue
    โœ” .ts
    โœ” .tsx
    โœ” .d.ts
    โœ– .ls
    โœ– .coffee
    โœ– .litcoffee
    โœ– .coffee.md
    โœ– .csx
    โœ– .cjsx

Typescript shows with โœ– but typescript is already installed in node_modules? (I verified using npm list)

I tried installing dependency-cruiser locally to see if that would help but did nothing.

  • If you've installed dependency-cruiser globally typescript needs to be installed globally as well in order for dependency-cruiser to find it. Judging from the command line script in your issue, you're using that.
  • If you run dependency-cruiser from a local install (so it's in your projects' node_modules and the binary is in ./node_nodules/.bin/depcruise) and typescript is installed locally, dependency-cruiser picks up that one.

Note that if you use depcruise on the command line you're using the globally installed one. So even if you install dependency-cruiser locally, it'll use the global one, and pick up any global compiler.

So you can do one of two things:

  • install typescript globally as well if you use the global depcruise
  • make sure to run the local depcruise script - either by calling call ./node_modules/.bin/depcruise directly (it's where the _scripts_ section of your package.json will look) or use npm's npx : npx depcruise ...

HTH

Hi @Ivanca I assume the answer in the previous comment sufficed to resolve the issue. If that isn't the case, feel free to re-open the issue with more details.

I'll add an entry to the FAQ as this is bound to come up more often.

Was this page helpful?
0 / 5 - 0 ratings