aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.3k stars 48 forks source link

aliases not working on declaration files in dist/ #117

Closed chirastefan closed 1 year ago

chirastefan commented 1 year ago

I'm using vite-tsconfig-paths for resolving aliases from the tsconfig.json file and vite-plugin-dts for generating .d.ts files and they work fine inside my project, but after I run build (in lib mode) and check the dist folder the imports aliases are not resolved. They point to the src folder, not the dist folder. Adding a relative path works though. Shouldn't the aliases be resolved on build?

Reproduction https://stackblitz.com/edit/vitejs-vite-b6n9u5?file=package.json

Steps to reproduce run npm install then npm run build

aleclarson commented 1 year ago

This plugin only affects Vite module resolution, which isn't responsible for type declaration file generation. This is actually a "bug" with TypeScript itself (see https://github.com/microsoft/TypeScript/issues/25677).

chirastefan commented 1 year ago

Meanwhile, I tried using aliases directly into vite.config.ts(without vite-tsconfig-paths) and it works, the aliases are transformed inside the generated .d.ts files. So I think this is an issue with vite-tsconfig-paths.

aleclarson commented 1 year ago

@chirastefan The resolve.alias option actually rewrites the code before vite-plugin-dts processes it. This plugin merely interprets the import as it's written and tells Vite which module the import is referring to.