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.

[Technical] Add baseUrl in tsconfig.json in order to avoid relative paths

See original GitHub issue

Now that the library has been migrated to typescript 🎉 I think we could use the baseUrl option

"baseUrl": "./

By doing so, we could set all the imports as absolute from that URL. So, for example, this import

import rule, { RULE_NAME } from '../../../lib/rules/no-debug';

can be now converted to

import rule, { RULE_NAME } from 'lib/rules/no-debug';

and the same applies to all import. I usually find this more readable

In addition to that, when moving files, they get updated automatically 😄

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Belco90commented, Jun 15, 2020

Ok so it seems we are introducing more problems than we solve. Should we close the issue then?

2reactions
nickmccurdycommented, Jun 15, 2020

I’ve maintained a TypeScript library using custom paths, and I don’t think it’s worth the effort. I spent way more time trying to fix tooling bugs than I saved by making imports absolute, and you can still simplify relative imports by just moving files around.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use paths in tsconfig.json? - Stack Overflow
Just specify the baseUrl, config will take care of your relative path. way to config: tsconfig.json file add the below properties.
Read more >
Documentation - Module Resolution - TypeScript
Use non-relative paths when importing any of your external dependencies. ... value of baseUrl property in 'tsconfig.json' (if given path is relative, ...
Read more >
How to set an absolute path in TypeScript | Towards the Cloud
This file contains the compiler options required to compile and run the project. You need to add the following properties: baseUrl and paths...
Read more >
Avoid Relative Path Hell in TypeScript Backend - Medium
When I start to create a new app in TypeScript, I tend to use relative import at the beginning. But as the app...
Read more >
Avoid relative path import hell in react - DEV Community ‍ ‍
You need to configure your application to support importing modules using absolute paths. This can be done by configuring a jsconfig.json or ...
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