Issue: Dependency cruiser is unable to correctly resolve aliases defined using "paths" in tsconfig that start with '/' (tsconfig-paths issue)

See original GitHub issue

We are currently using ViteJS as our devServer, and the condition to define alias there is that it should start with a forward slash (/). If you want to know why is that the case, checkout this link.
Thus our paths property in tsconfig.json looks like this

"paths": {
  "/@utils/*": ["src/utils/*"]
  "/@services/*": ["src/services/*"],
  "/@contexts/*": ["src/contexts/*"],
  "/@src/*": ["src/*"]
},

Earlier when we were using the aliases without / dependency cruiser was working perfectly fine, eg: defining alias like "@utils/*": ["src/utils/*"], works.

Expected Behavior

Dependency cruiser should be able to resolve the aliases correctly

Current Behavior

It is not able to resolve the aliases correctly. As can be seen from the example shared below to reproduce the issue, it’s treating the alias as a separate directory. link

Possible Solution

Not sure.

Steps to Reproduce (for bugs)

Following repo can be used to reproduce the issue https://github.com/surgicaI/dependency-cruiser-repro

Context

We want to use dependency cruiser to add forbidden dependency tests and due to this bug we are not able to do so.

Your Environment

  • Version used:9.8.0
  • Node version:14.7.0
  • Operating System and version:MacOS Catalina
  • Link to your project:N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sverweijcommented, Nov 18, 2020

@surgicaI Found the root cause: dependency-cruiser uses tsconfig-paths-webpack-plugin for handling tsconfig paths. That in its turn uses tsconfig-paths which at the moment doesn’t work (yet, I hope) with path names that start with a /. An issue for this already exists in the tsconfig-paths repo: issue 128: “Does not work for path mapping starting with /). The suggested fix in that issue looks fairly simple, so I wonder why nobody made a pull request yet…

So this needs to be fixed upstream, or dependency-cruiser needs to start looking for alternatives for tsconfig-paths-webpack-plugin.

0reactions
sverweijcommented, Jul 30, 2022

@slaivyn / @surgicaI - it seems now

… the upstream bug seems to have been fixed. I’ve bumped the tsconfig-paths-webpack plugin to latest and shipped it in dependency-cruiser@11.13.1, which is on npm as of now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript — How to solve the problem with unresolved path ...
The actual cause of the issue is that the tsc compiler does not transpiles correctly the path aliases to absolute (real) paths.
Read more >
Cannot find module that is defined in tsconfig `paths`
I faced the same issue. I tried many things and now i got a solution which works for me. I have an app...
Read more >
How to handle tsconfig path aliases : r/typescript - Reddit
I've hit the ageold "Failed to load module..." error, where it can't resolve my path alias of "@something". I was using the Live...
Read more >
@reactivex/rxjs | Yarn - Package Manager
types: Resolved an issue where referencing Symbol.observable before RxJS accessed the symbol/observable module internally would result in a reference error.
Read more >
license_scanning (#2758) · Jobs · osm / NG-UI · GitLab
5 "path": "/builds/gitlab/osm/ng-ui/node_modules/d3-selection", ... See [#59](https://github.com/d3/d3-transition/issues/59).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found