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

When codesplitting on server runtime, .js with typedefs files are created instead of .d.ts #547

Closed
sannajammeh opened this issue Jun 13, 2024 · 4 comments · Fixed by #569
Labels
area:bug Something isn't working

Comments

@sannajammeh
Copy link

image

Adding .server-runtime or .shared-runtime to a file causes the bundler to codesplit correctly, but rather than creating a corresponding .d.ts extension file it will add a .js extension and dump the declarations in there.

@sannajammeh sannajammeh changed the title When codesplitting .js with typedefs files are created instead of .d.ts When codesplitting on server runtime, .js with typedefs files are created instead of .d.ts Jun 13, 2024
@amannn
Copy link

amannn commented Jun 13, 2024

I just ran into the same issue.

Here's a reproduction: amannn/bunchee-test@a9e6ce6

The relevant part is that there's a type created in the shared runtime that is then referenced in an entry point. As a result, the file dist/utils-shared-BdVwpBM3.js is created which contains only the type declaration and should therefore use .d.ts.

Using a .js file causes a TypeScript error for consumers in my project:

TS8017: Signature declarations can only be used in TypeScript files.

@huozhi
Copy link
Owner

huozhi commented Jun 13, 2024

It seems have some issues with codesplit, maybe I should mark this shared-runtime feature as experimental..as it's not super reliable now. I would probably go with sth else in #540

@sannajammeh
Copy link
Author

It seems have some issues with codesplit, maybe I should mark this shared-runtime feature as experimental..as it's not super reliable now. I would probably go with sth else in #540

We might stay on this route as we heavily rely on .server-runtime. We had issues where a client module still wouldn't codesplit correctly until the server module was marked .server-runtime

I hope #540 also supports react server only runtime declarations.

@sannajammeh
Copy link
Author

@amannn @huozhi
As a temporary fix, I implemented a postbuild step which assumes the default structure from bunchee prepare. Modify it to your liking.

https://gist.github.com/sannajammeh/0d2ef984d9a076a90dae9ba27910ea5e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants