Update app.bundle.js file


#1

Hi,

I just added a moment.js library in my project by this command “npm install moment --save”, calling moment() displaying errors in console.

Do i have to update app.bandle.js file before calling it, if yes then how m i suppose to do that.

Thanks


#2

If you want to use moment.js in your app then it’s not npm that you must use, it’s bower.
npm is used to install tools.

bower install moment --save

Then depending on the gulp process you use, you may have to insert a script link to moment.js in your index.html


#3

@gmarziou I believe your answer is targeted at Ionic 1 as Ionic 2 doesn’t use bower or gulp (it uses npm and webpack).

As for the OP – I haven’t tried momentjs yet but I was able to get lodash working for myself. I just npm i lodash --save, then inside my component I included import {zip} from 'lodash'; and I had access to lodash’s zip function inside my component’s class.


#4

I was able to add momentjs to my component. After installing moment using npm (npm i moment --save) you need to go into your component and import it.

Example:

import {Page} from 'ionic/ionic';
import * as moment from 'moment';

@Page({
  templateUrl: 'app/my-component/test-moment.html',
  directives: []
})
export class TestMoment {
  
  constructor() {
    console.log(moment);
  }

}

I’m using typescript, but I believe the ES6 import is the same format.

Note: I needed to also quit and restart ionic using ionic serve.


#5

@BCKrueger thanks man i will give it a try and let you know.


#6

Right, sorry I did not notice the tag.


#7

This seems to have broken in ionic2 beta 3, any idea how I can add libraries now? Following the above I get

ERROR in [default] /......./app/app.ts:6:24 
Cannot find module 'moment'.

#8

@ctcampbell with TypeScript you also have to install the type definitions (check out the linked post for details):