Rollup says "[name] is not exported by [file]" while it clearly is

Viewed 640

I am building a Svelte/TypeScript application and all of a sudden it won't compile anymore, with the following error:

[!] Error: 'VoidPromiseCallback' is not exported by src/types.ts, imported by src/TopicEditionFormStack/TopicEditionFormStack.svelte
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
src/TopicEditionFormStack/TopicEditionFormStack.svelte (2:18)
1: <script lang="ts">
2:   import { Topic, VoidPromiseCallback } from '../types.js';
                     ^

However if you look at file src/types.ts you see at the end:

export type VoidPromiseCallback = {
  resolve: () => void,
  reject: (reason?: any) => void,
}

VS Code agrees that types.ts does export the name, since if I do “go to definition” on the occurrence of VoidPromiseCallback Rollup complains about, it navigates to the export quoted above.

Any idea what could cause this? I was thinking maybe Rollup did not invalidate a cache regarding the exports of types.ts.

1 Answers

In a svelte component you will need to import your types by specifying that what you import is a type:

import { Topic } from '../types.js';
import type { VoidPromiseCallback } from '../types.js';
Related