Resolve path alias in declaration files (`.d.ts`)
See original GitHub issueWhen applying a path alias to a typescript project, the path is resolved in the emitted javascript files, but not in the declaration files.
Versions
- typescript: 3.7.4
- rollup: 1.27.14
- rollup-plugin-typescript2: 0.25.3
In the following project I have aliased ~/*
to ./src/*
. Allowing for imports using absolute paths from the base directory.
https://github.com/alshdavid-sandbox/rollup-typescript-library
npm install && make
cat dist/a/index.d.ts | grep "~"
cat
should print nothing, however it currently prints
import { B } from '~/b';
This illustrates that we are not applying path resolution to the declaration files.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:35
- Comments:24 (3 by maintainers)
Top Results From Across the Web
Typescript declaration file created with alias instead of relative ...
The type declaration file contains alias instead of relative path. How to fix this problem? import { bar } from "./utils/bar. ts export...
Read more >Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
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 – How to solve the problem with unresolved path ...
This error actually points to the transpiled('emitted') JavaScript .js file containing the line with the path alias. The actual cause of the ...
Read more >Setting up Path Alias in TypeScript and tsc build without error
What it does is to look for your source file (.ts) and find the relative path to each module you set as path...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, I am achieving this using ttsc as well. I was unable to get the transformers working directly with rollup-plugin-typescript2
transformers
options, so I opted to usettsc
My rollup config looks like:
Same issue with
ttypescript
andtypescript-transofrm-paths
, it didn’t work :disappointed. When running build:But using
@zerollup/ts-transform-paths
andttypescript
it works 🎉There is an awesome setup here: https://www.npmjs.com/package/@zerollup/ts-transform-paths#setup-for-rollup-plugin-typescript2
rollup.config.js
tsconfig.json