Importing my own external JS library in Ionic 3 project


Hi, I searched about this issue a lot before opening a new thread but I still haven’t fixed my code.

I’m trying to include my javascript file myLibrary.js into my project and i’ve done it by adding the script tag into index.html and declaring var ext:any into the .ts file where i’m supposed to use my functions but when i call ext.myFunction() I get this:

ReferenceError: ext is not defined

The only way i can make it works it’s by removing the line “declare var ext:any” and calling myFunction() just like that but obviously the editor notices he can’t find the function( even though the code run perfectly)

What am i doing wrong?

Thanks for your time

  1. Your library should have typings. Better way to create library for ionic (e.g. for angular) is to use generator-angular2-library
  2. To use this library you need to:
    2.1 publish generated library to npm
    2.2 install your published library to your project with npm install --save-dev your-library-name
    2.3 create file declarations.d.ts in your project
    2.4 add this file directly to your tsconfig.json
    2.5 let’s say, that your library has name custom-library, then declarations.d.ts should have line
declare module 'custom-library';