【发布时间】:2017-07-21 17:20:37
【问题描述】:
我正在尝试为 fabric (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/fabric/) 安装类型定义,但我无法找出正确的类型命令。
一开始我尝试typings install dt~fabric --global --save 并得到以下错误:
$typings install dt~fabric --global --save
typings ERR! message Attempted to compile "fabric" as a global module, but it looks like an external module. You'll need to remove the global option to continue.
然后我尝试了typings install dt~fabric --save,typings 命令成功但typings/modules/fabric/index.d.ts 文件与原始文件https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/fabric/index.d.ts 不同。
typings 命令用declare module 'fabric' {} 包装原始内容,这会在.d.ts 文件内的语句export as namespace fabric; 处导致编译器错误Error:(9, 1) TS1316:Global module exports may only appear at top level.。
打字版本 2.1.0
【问题讨论】:
-
你试过
npm install --save @types/fabric吗? -
没有
@types/fabric -
我很确定有。你错过拼写了吗?
-
@AnyName 是的,你是对的......我现在找到了。但是又出现了一个问题,“Uncaught TypeError: fabric.Canvas is not a constructor”,比如stackoverflow.com/questions/36984795/…在使用webpack时,有什么想法吗?
-
我解决了,我使用
<script>标签并在webpack中包含"fabric": "fabric"externals,谢谢你的帮助
标签: typescript fabricjs