【问题标题】:@types/tabulator-tables breaking tabulator-tables import@types/tabulator-tables 打破制表符表导入
【发布时间】:2021-08-27 04:59:08
【问题描述】:

安装以下内容(从 tabulator-tables@4.9.1 开始):

npm install tabulator-tables
npm install @types/tabulator-tables

然后进行以下导入

import Tabulator from 'tabulator-tables';

导致错误:Module Usage (Error node_modules @types tabulator tables index.d.ts' is not a module)

改为使用此导入

import 'tabulator-tables';

不输出错误,并允许加载类型信息,但在运行时(例如,在 Angular 12 项目上)实际上不允许访问 Tabulator 对象,从而导致类似 ReferenceError: Tabulator is not defined 的错误。

【问题讨论】:

    标签: angular typescript tabulator definitelytyped


    【解决方案1】:

    这是由于@types/tabulator-tables 中的类型定义文件中缺少默认导出。不幸的是,在上游添加默认导出是不可行的,因为它会破坏现有的代码库。

    幸运的是,有一个解决方法,described here:如果您还没有创建一个 index.d.ts 文件,并在其中添加以下行:

    declare module "tabulator-tables" { export = Tabulator; }
    

    (请确保还包含 index.d.ts 文件,方法是将其列在 "files" 中,或确保它与 tsconfig.json 中 "includes" 中的模式匹配。您可能还需要设置 @987654328 @在"compilerOptions"。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多