在角度2/4中使用UMD库

时间:2017-07-29 06:49:01

标签: javascript angular requirejs umd

我有编译到Tus.io的库(UMD)。我需要在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'.

1 个答案:

答案 0 :(得分:2)

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

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

并像这样导入:

import * as tus from "tus-js-client";