question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript tsconfig.json path-mapping not being used

See original GitHub issue

Context: https://stackoverflow.com/questions/37372816/what-does-symbol-mean-in-import-component-from-angular-core-statem https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping

Our app has imports like: import { Foo } from "@services/foo"; with the following in tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".", // This must be specified if "paths" is.
    "paths": {
      "@service": ["src/app/services/*"] // This mapping is relative to "baseUrl"
    }
  }
}

Then depcheck outputs:

Missing dependencies
* @services/foo: ./src/bar.ts

Expected behavior: depcheck should find and read paths in tsconfig files.

PS: Not sure, but maybe https://github.com/depcheck/depcheck/issues/544 is related.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

16reactions
rumplcommented, Jul 26, 2020

Cause path alias are widely used.

They shouldn’t be 😃

8reactions
rumplcommented, Nov 15, 2020

Here’s my take on why I don’t want to implement this in depcheck.

I am not a fan of it. That’s just an opinion granted, but I would like to think my opinion is important for my project.

Path aliases add an unnecessary indirection, I have worked on multiple project that use them and, as a new developer to the project, I found it very hard to know just from looking at the code if an import is a local one or one from a dependency. It’s also hard, for someone new, to know and remember all the path aliases. The tooling around is pretty much non-existent so my IDE is always complaining about unknown dependencies.

I you look at the examples in the typescript documentation you can see that they talk about paths as a tool for some exceptional setups (modules not under baseUrl, generated code, etc). The --ignores flag exists exactly for these exceptional cases. The problem here is that, instead of using lerna/webpack workspaces you use aliases.

Would you accept PR’s?

I’m torn, really torn, you’ll open the PR and then I’m left maintaining something I don’t want to maintain and don’t like… So no.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are these tsconfig paths not working? - Stack Overflow
In case anyone is using VSCode and having trouble getting the /* solution to work. Try Cmd+Shift+P > Typescript: Restart TS Server. –...
Read more >
Tsconfig.json is not being used on 0.78.1 - support - HUGO
I'm using for my website a module written with Typescript. It has a tsconfig.json that contains a path mapping configuration:
Read more >
Documentation - Module Resolution - TypeScript
The TypeScript compiler supports the declaration of such mappings using paths property in tsconfig. json files. Here is an example for how to...
Read more >
Paths mapping | ts-jest - GitHub Pages
If you use "baseUrl" and "paths" options in your tsconfig file, ... option in your Jest config is setup accordingly. ... tsconfig.json
Read more >
tsconfig.json path mapping not working in Nuxt.js project
json file with the following path mappings. Unfortunately, the editor is flagging any import that uses these paths in our vue and js...
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