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.

Support absolute URL for typescript

See original GitHub issue

Would be good to have a useAbsolute flag when generating libraries, this could be a universal flag that applies to all typescript projects.

Description

Allow baseUrl to be applied, we’ll need a third party plugin to transform the absolute paths to relative during compilation

Motivation

Enables absolute URL for project, cleaner imports

Suggested Implementation

Take @nrwl/node:package for example, We would need to modify compiler used here:

https://github.com/nrwl/nx/blob/c7b0e7d12284a8045b057c1addaa3d701a1adf9f/packages/node/src/builders/package/package.impl.ts#L205-L208

Compiler: https://github.com/cevek/ttypescript/tree/master/packages/ttypescript Plugin: https://github.com/zerkalica/zerollup/tree/master/packages/ts-transform-paths

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

2reactions
shlajincommented, Feb 13, 2021

I would love to see absolute imports not only for libraries, but for everything within one package. A simple example would be shortening this

import IconTrash from '../../../../../../assets/icons/IconTrash';

to this

import IconTrash from '~/src/assets/icons/IconTrash';

Note that I don’t want to specify the package name with the absolute import, this helps me keep packages within boundaries and it makes moving / renaming easier if necessary.

0reactions
Yedidyarcommented, Dec 1, 2022

I would love to see absolute imports not only for libraries, but for everything within one package. A simple example would be shortening this

import IconTrash from '../../../../../../assets/icons/IconTrash';

to this

import IconTrash from '~/src/assets/icons/IconTrash';

Note that I don’t want to specify the package name with the absolute import, this helps me keep packages within boundaries and it makes moving / renaming easier if necessary.

Has anyone solved this problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set an absolute path in TypeScript | Towards the Cloud
Absolute file paths can help organize the imports in your TypeScript projects by improving the way import locations are fetched by the ...
Read more >
How to use absolute path with Typescript? - Stack Overflow
I have a project that written in Typescript on NodeJS. I am using relative path for my modules to import another. But this...
Read more >
Documentation - Module Resolution - TypeScript
A non-relative import can be resolved relative to baseUrl , or through path mapping, which we'll cover below. They can also resolve to...
Read more >
Advanced Features: Absolute Imports and Module Path Aliases
Absolute Imports and Module path aliases ... Next.js automatically supports the tsconfig.json and jsconfig.json "paths" and "baseUrl" options since Next.js 9.4.
Read more >
Dependency resolution - Parcel
Typically, these dependencies do not specify a full absolute path, ... In addition to the standard dependency specifiers supported across many tools, ...
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