Search code examples
javascriptangularrequirejsumd

use UMD library in angular 2/4


I have library (Tus.io) thats compiled to UMD. i need it in my Angular2/4 project. when i install it with npm ( npm install tus-js-client ) and import it (var tus = require("tus-js-client"); ) the error i get is:

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'.

Solution

  • The simplest solution to your problem is to install the TypeScript declarations:

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

    And to import it like this:

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