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

[Bug]: Barrel file export with TypeScript type breaks import #8078

Closed
andreme opened this issue Oct 10, 2024 · 2 comments
Closed

[Bug]: Barrel file export with TypeScript type breaks import #8078

andreme opened this issue Oct 10, 2024 · 2 comments
Assignees
Labels
bug Something isn't working pending triage The issue/PR is currently untouched.

Comments

@andreme
Copy link

andreme commented Oct 10, 2024

System Info

rs build 1.0.8

Details

When a barrel file exports both a TS type and a function, the build fails with an error about the type. Commenting out the export for the type makes the build succeed.

export {DummyType, testFunc} from './dummy' // fails
// export {/*DummyType,*/ testFunc} from './dummy' // works
// dummy.ts
export interface DummyType {
    a: boolean
}

export function testFunc() {
    console.log('test')
}

Reproduce link

https://github.com/andreme/rsbuild-barrel-file-error

Reproduce Steps

Run pnpm build

Error:

File: /workspaces/rspack-repro/src/dummy_export.ts:1:1
  × HarmonyLinkingError: export 'DummyType' (reexported as 'DummyType') was not found in './dummy' (possible exports: testFunc)
   ╭─[1:0]
 1 │ export { DummyType, testFunc } from './dummy'; // fails
   · ──────────────────────────────────────────────
 2 │  // export {/*DummyType,*/ testFunc} from './dummy' // works
   ╰────
@andreme andreme added bug Something isn't working pending triage The issue/PR is currently untouched. labels Oct 10, 2024
@markmssd
Copy link

In case that helps you get unblocked, as a workaround we import the type first, then re-export it:

import { DummyType } from './dummy'

export { testFunc } from './dummy'
export { DummyType }

@JSerFeng
Copy link
Collaborator

Because we can only see single typescript file at present, there is no information that can let Rspack know that DummyType is a type.

Here are solutions that can help you:

  1. export {type DummyType } from "./dummy" this way Rspack can know that DummyType is type
  2. Use this config to ignore the error

@JSerFeng JSerFeng self-assigned this Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage The issue/PR is currently untouched.
Projects
None yet
Development

No branches or pull requests

3 participants