Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript path alias not resolved in emited declarations #25

Open
5 tasks done
pradel opened this issue Oct 1, 2024 · 4 comments
Open
5 tasks done

Typescript path alias not resolved in emited declarations #25

pradel opened this issue Oct 1, 2024 · 4 comments

Comments

@pradel
Copy link

pradel commented Oct 1, 2024

Describe the bug

Hi, I am integrating this plugin and found out that the typescript path alias are not resolved in the emited declarations.

If in your code you write

import { a } from "@/utils";
export { a };

with the following ts paths config

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

The .d.ts file as the same output

import { a } from "@/utils";
export { a };

What I would be expecting is that the path is resolved to produce a valid declaration file like this

import { a } from "./utils";
export { a };

The result is that the emited declarations are not working in packages importing them as they don't know how to resolve the paths alias.

Reproduction

https://codesandbox.io/p/devbox/issue-isolated-declarations-paths-39pdg8

System Info

System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (2) x64 AMD EPYC
    Memory: 1.75 GB / 4.01 GB
    Container: Yes
    Shell: Unknown
  Binaries:
    Node: 20.12.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.5.0 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/share/npm-global/bin/pnpm

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@sxzz
Copy link
Member

sxzz commented Oct 1, 2024

Path alias will not be resolved even if you're using native tsc.

@pradel
Copy link
Author

pradel commented Oct 1, 2024

Interesting, I just tried with tsc and indeed the same is happening, do you know why? The declarations for packages that consume them are invalid.
And is there any workaround to get it to work with this plugin?

@sxzz
Copy link
Member

sxzz commented Oct 1, 2024

Essentially, this issue faces the same problem as #23; dts packaging cannot leverage rollup/esbuild's own path resolver/rewriter. I haven't thought of a good solution yet 🤔

@marcalexiei
Copy link
Contributor

Gotcha, thanks for your review on #23.
just to add some context:
I'm trying to migrate my build toolchain to swc and unplugin-isolated-decl from @rollup/plugin-typescript.

dts packaging cannot leverage rollup/esbuild's own path resolver/rewriter

With the typescript plugin the declaration were emitted in the original folder (relative to the module root) so they were not included inside the folder with the index.js file.

To better explain what I'm talking about I created a small example here:
https://github.com/marcalexiei/unplugin-isolated-decl-bugs/tree/nested-declarations-with-ts

I haven't thought of a good solution yet 🤔

Maybe the typescript plugin approach could be used to solve both these issues.


Probably you are already aware of all this, but I just want to help with the little I know so far 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants