Monday, 25 March 2019

How to use third party javascript library with ionic4 and capacitor?

What is the correct way to install third party javascript libraries with an Ionic 4 angular app and Capacitor?


I tried to install the crunker library as follows:

npm install crunker --save

Then ...

import * as crunker from 'crunker';
...
export class MyPage {

  constructor() {}

  doX() { 
     const crunk = new crunker.Crunker();
     ...
  }
  ...
}

Followed by:

npm run build
npx cap copy
npx cap copy ios
npx cap open ios

However, when I hit the page in the IOS simulator, I see the following error in the console:

TypeError: undefined is not a constructor (evaluating 'new crunker__WEBPACK_IMPORTED_MODULE_4__"Crunker"')



from How to use third party javascript library with ionic4 and capacitor?

No comments:

Post a Comment