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.

Allow Typescript absolute path alias

See original GitHub issue

Hey, currently the absolute paths from my typescript tsconfig.json are not resolved.

{
  "compilerOptions": {
    "paths": {
      "@svgs/*": [
        "svgs/*"
      ]
  }
}

Doing import Dog from '@svgs/dog.svg' results in an error: Cannot find module '@svgs/dog.svg' from '/Users/lukasoppermann/Repos/next-app/components'

Is there a way to make this work?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
lukasoppermanncommented, Jan 11, 2021

It seems to be working fine just by installing the babel module-resolver and adding the following to the .babelrc and leaving the tsconfig.json as is.

// babelrc
{
  "presets": ["next/babel"],
  "plugins": [
    "inline-react-svg",
    ["module-resolver", {
      "root": ["./"],
      "alias": {
        "@svgs": "./svgs"
      }
    }]
  ]
}
///
0reactions
ljharbcommented, Jan 11, 2021

Good call; as long as you’re OK duplicating the config in both babel and TS configs, that should work fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Path aliases with TypeScript in Node.js
I've just released a new package Alias HQ, which allows you to reuse your js/tsconfig.json path aliases in Webpack, Jest, Rollup, or any...
Read more >
Path aliases with TypeScript in Node.js - Level Up Coding
With path aliases, you can declare aliases that map to a certain absolute path in your application. ... Let's get into it and...
Read more >
How To Configure Path Aliases With TypeScript
The path is based on the location of my tsconfig. json file. For this example, I'll set baseUrl to the root of my...
Read more >
How to configure and resolve path alias with a Typescript Project
Path alias is a way to define an absolute path in your typescript project with a word, path or a character.
Read more >
TypeScript Path Aliases
Path Alias is a TypeScript configuration that maps a custom alias to a path in your project. Thanks to path aliases, the import...
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