justkey007 / tsc-alias

Replace alias paths with relative paths after typescript compilation
MIT License
894 stars 62 forks source link

Libraries imports are replaced with alias #209

Closed Andynopol closed 8 months ago

Andynopol commented 9 months ago

If you have a directory named as a library(ex: redux) tsc-alias replaces the import paths to the redux library with the ones to the local directory.

How to reproduce:

"baseUrl":"./"
"paths":{
   "@redux":["src/redux"],
   "@redux/*":["src/redux"]
...
}

"build": "tsc && tsc-alias -p ./tsconfig.json"

Compile result:

declare const _default: import("redux").Reducer<TYPE>;

After tsc-alias:

declare const _default: import("../../../redux").Reducer<TYPE>;

In my case, I am trying to compile a react library I am working on.

Here is the tsconfig.json:

{ "compilerOptions": { "strict": true, "jsx": "react-jsx", "declaration": true, "esModuleInterop": true, "removeComments": true, "allowJs": true, "allowSyntheticDefaultImports": true, "outDir": "dist", "target": "ESNext", "module": "CommonJS", "moduleResolution": "node", "baseUrl": "./", "paths": { "@rdx": ["src/rdx"], "@rdx/": ["src/rdx/"], } }, "include": ["src/*/"], "exclude": ["packages/@interactjs/**", "example"] }

I replace redux with rdx, but still, this is not an expected result and may take time for someone to remark this.

tphalp commented 8 months ago

I'm running into the same situation. I'm using the npm module, redux, and it's replacing it with ../redux, which is also a folder that I have in my project structure.

justkey007 commented 8 months ago

https://github.com/justkey007/tsc-alias/discussions/110