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

Unbuild: Dynamic imports #395

Closed
nethriis opened this issue May 5, 2024 · 2 comments
Closed

Unbuild: Dynamic imports #395

nethriis opened this issue May 5, 2024 · 2 comments

Comments

@nethriis
Copy link

nethriis commented May 5, 2024

Discussed in unjs/community#6

Originally posted by nethriis May 4, 2024
Hi, does anyone know how to dynamically import TypeScript files with unbuild in ESM? I have this code:

export const command = {
  ping: () => import(findPath('ping')).then(m => m.default || m)
}

However, during the prepack with unbuild, I don't see a 'chunks' folder, and consequently there's an import issue for this file.

@pi0 pi0 transferred this issue from unjs/community May 7, 2024
@pi0
Copy link
Member

pi0 commented May 7, 2024

Mirror from unjs/unstorage#440

nethriis: When the argument of import is a static string like './commands/ping' the chunks folder is generated on prepack and everything works well but with a variable, in my case findPath('ping') the chuncks folder is not generated

@pi0
Copy link
Member

pi0 commented May 7, 2024

Hi. You need to pass statically analazable paths to both static and dynamic imports this way rollup can properly resolve them during build and bundle/make chunks.

It should be something like import('./path/to/ping.ts') for example.

@pi0 pi0 closed this as completed May 7, 2024
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

2 participants