【问题标题】:Rollup says "[name] is not exported by [file]" while it clearly isRollup 说“[name] 不是由 [file] 导出的”,而它显然是
【发布时间】:2021-10-21 20:20:23
【问题描述】:

我正在构建一个 Svelte/TypeScript 应用程序,突然间它不再编译,出现以下错误:

[!] 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';
                     ^

但是,如果您查看文件 src/types.ts,您会在末尾看到:

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

VS Code 同意 types.ts 确实导出了名称,因为如果我在出现 VoidPromiseCallback Rollup 抱怨时执行“转到定义”,它会导航到上面引用的导出。

知道是什么原因造成的吗?我在想也许 Rollup 没有使关于 types.ts 导出的缓存失效。

【问题讨论】:

    标签: typescript svelte rollupjs


    【解决方案1】:

    在一个苗条的组件中,你需要通过指定你导入的是一个类型来导入你的类型:

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

    【讨论】:

    • 成功了,非常感谢!我没有考虑这一点,因为我导入的其他“类型”实际上是类,并且规则似乎与类有点不同,如果所有类都仅用作类型,则只需要 import type。不知道如果没有你的回答,我会花多长时间调试!
    猜你喜欢
    • 2022-01-02
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 2014-10-27
    • 2022-06-12
    • 1970-01-01
    • 2022-11-27
    • 1970-01-01
    相关资源
    最近更新 更多