2

我有编译为UMD的库( Tus.io ) 。我在我的 Angular2/4 项目中需要它。当我使用 npm 安装它(npm install tus-js-client)并导入它(var tus = require("tus-js-client");)时,我得到的错误是:

Failed to compile.
/home/***/src/app/manageVideos/Partials/add.component.ts (8,17): 
Module '../../../../node_modules/tus-js-client/dist/tus.js' 
was resolved to '/home/***/node_modules/tus-js-client/dist/tus.js', 
but '--allowJs' is not set.
/home/***/src/app/manageVideos/Partials/add.component.ts (9,11): Cannot find name 'require'.
4

1 回答 1

2

解决问题的最简单方法是安装 TypeScript 声明:

npm install @types/tus-js-client --save-dev

并像这样导入它:

import * as tus from "tus-js-client";
于 2017-07-29T07:13:13.573 回答