Skip to content

unbundle: true generates unexpected virtual runtime file when using typeof import() in exported typesΒ #379

@m1rn

Description

@m1rn

Reproduction link or steps

Problem Description

When using unbundle: true configuration in tsdown, exported type declarations containing direct typeof import('./module') expressions cause the build to generate an unexpected dist/_virtual/rolldown_runtime.js file. This virtual runtime file appears to be unnecessary since the typeof import() expression is purely a type operation that should be erased during compilation.

Steps to Reproduce

  1. Create a tsdown.config.ts file with:
    export default {
      dts: true,
      unbundle: true
    };
  2. Create a worker module:
    // worker.ts
    export function workerMethod() {}
  3. Create a main file with an exported type:
    // index.ts
    export type WorkerMethodNames = keyof typeof import('./worker');
  4. Run the build: tsdown build
  5. Observe the output directory contains dist/_virtual/rolldown_runtime.js

Live Reproduction:
https://stackblitz.com/edit/tsdown?file=package.json

What is expected?

Not generate any virtual runtime files for pure type expressions

What is actually happening?

Generates dist/_virtual/rolldook_runtime.js containing runtime code

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions