SukkaW / rollup-plugin-swc

Use SWC with Rollup to transform / minify ESNext and TypeScript code.
MIT License
154 stars 15 forks source link

Cannot handle export ts type #47

Closed huozhi closed 1 year ago

huozhi commented 1 year ago

Expect behavior

I can export ts type in ts entry file, and in output it could be erased in js asset. And rollup won't complain about resolving

Observed behavior

src/index.ts → stdout...
(!) Missing exports
https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
src/index.ts
IConfig is not exported by src/types.ts
1: import { IConfig } from './types';
            ^
2:
3: export { IConfig }
[!] RollupError: "IConfig" is not exported by "src/types.ts", imported by "src/index.ts".
https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
src/index.ts (1:9)
1: import { IConfig } from './types';
            ^
2:
3: export { IConfig }

Reproduction

https://github.com/beeebox/swc3-export-type-repro

SukkaW commented 1 year ago

Thanks for the report, I will look into this!

SukkaW commented 1 year ago

@huozhi

I've found the cause of the issue. But as it stands, it seems unfixable:

You can workaround the issue by explicitly declaring IConfig as a type-only import:

import type { IConfig } from './types';
// or
import { type IConfig } from './types';

This can be enforced / auto-fixed through the use of the @typescript-eslint/eslint-plugin with the @typescript-eslint/consistent-type-imports rule:

"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports" }]