Search code examples
angulartypescript1.8typescript-typings

Typescript Typings in ANgular 2 library package


Trying to build reusable Angular 2 library containing components and directives etc.. written in Typescript That can be used by other developers by NPM install. The library also has third party package dependencies that have Typescript definitions but are not written in Typescript.

The problem I am having is that the application that is using the angular2 library must also have reference to the third party package that is a dependency of the library.

Angular2 SPA [MyMainApp] uses a library of Angular2 components services and directives packages as an NPM package [MyLib]. MyLib uses third party NPM packages as well. Everything compiles but when I run MyMainApp I get 404 errors for the third party packages installed into MyLib.

MyLib > npm install perfect-scrollbar

MyMainApp > npm install MyLib

When I run MyMainApp i get: zone.js:101 GET http://localhost:3000/perfect-scrollbar 404 (Not Found)

inside the directive that uses perfect-scrollbar

import { initialize, destroy } from 'perfect-scrollbar';

Solution

  • In fact, there are two parts:

    • Compilation. Typings apply at this level only and take part of type checking
    • Runtime. At the level, the module manager is responsible for loading your module against a name.

    Because you have a 404 error when executing your application, I find that your perfect-scrollbar module isn't correctly configured in SystemJS.