Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

TypeError: Cannot read property 'utc' of undefined #104

Closed
jhonjairoroa87 opened this issue Jan 12, 2015 · 19 comments
Closed

TypeError: Cannot read property 'utc' of undefined #104

jhonjairoroa87 opened this issue Jan 12, 2015 · 19 comments

Comments

@jhonjairoroa87
Copy link

I have just added angular-moment in my angularjs project and Im getting the error "TypeError: Cannot read property 'utc' of undefined"

In the following link I found out that the only option is to downgrade the momnetjs version:

http://stackoverflow.com/questions/26642479/angular-moment-cannot-read-property-utc-of-undefined

"Apparently, since v2.4 moment is not a global object any more, which resulted in 'undefined' everytime angular-moment made a reference to moment.

I switch to v.2.3.1, it works like a charm now"

@urish
Copy link
Owner

urish commented Jan 12, 2015

Did you remember to include moment.js in your project?

@jhonjairoroa87
Copy link
Author

Yes I did.

@urish
Copy link
Owner

urish commented Jan 12, 2015

So, if you could create a plunkr/jsfiddle that reproduces the issue that would be great. Thanks!

@murilomothsin
Copy link

I have the same error in my app.

I just change the order of includes and works fine!

<script src="app/assets/js/moment-with-locales.js"></script> <script src="app/assets/js/angular-moment.min.js"></script>

@w9ahmed
Copy link

w9ahmed commented Feb 7, 2015

I'm having the same issue!
SOLVED
I had to import moment:
< script src="moment/moment.js" > </script>
< script src="/angular-moment/angular-moment.min.js" > </script>

in that order!

@EladBezalel
Copy link

i'm having the same problem, i'm including both moment.js and angular-moment

The problem seems to be that angular couldn't inject moment and its undefined

@w9ahmed
Copy link

w9ahmed commented Mar 3, 2015

@EladBezalel Are you sure about the import order?
import moment.js first and then angular-moment.

@EladBezalel
Copy link

Yes.. The order is fine..

@EladBezalel
Copy link

I figured out it was a problem with moment problem because its not working properly with node webkit.

@katrotz
Copy link

katrotz commented Apr 14, 2015

Same problem here. I use JSPM/SystemJS for package management/module loading.
moment is loaded in AMD format, while angular-moment is forced to global.

'format global';
/* global define */
'deps angular';
'deps moment';

which forces to load moment via global angularMoment(angular, window.moment); and in my case it is undefined.

if (typeof define === 'function' && define.amd) {
        define(['angular', 'moment'], angularMoment);
    } else if (typeof module !== 'undefined' && module && module.exports) {
        angularMoment(angular, require('moment'));
        module.exports = 'angularMoment';
    } else {
        angularMoment(angular, window.moment);
    }

@EladBezalel
Copy link

My temporary solution is to install moment from npm and define it global:

var moment = require('moment');

@urish urish closed this as completed in ab6b225 May 1, 2015
@urish
Copy link
Owner

urish commented May 1, 2015

Thanks for everyone who participated. This is now fixed and released as 0.10.1

@nikolai-b
Copy link

Just in case this helps someone else.
With release 0.10.1 I was still getting problems with this until I put

< script src="moment/moment.js" > 

before angular.js (not just before angular moment).

@honitus
Copy link

honitus commented May 10, 2015

Thanks @nikolai-b your tip fixed my issue.

@urish This issue needs to be re-opened.

@cmgustavo
Copy link

I had the same issue with nw.js (node-webkit). This was solved updating angular-moment to 0.10.1 and moment to 2.10.3.

Thanks!

@Chalkin
Copy link

Chalkin commented May 29, 2015

having same issue here.

using moment.js 2.10.3
angular-moment.js 0.10.1

I added angularjs moment to my app.js and attached the angularMomentConfig

var app = angular.module('app', [
    'ui.router',
    'angularMoment'
])
.constant('angularMomentConfig', {
    preprocess: 'utc',
    timezone: 'Europe/Berlin'
})

regarding order, i have tried following orders (and others):

jquery.js
moment.js
moment-timezone.js
angular.js
angular-moment.js
app.js

jquery.js
moment.js
angular.js
angular-moment.js
app.js
moment-timezone.js

jquery.js
angular.js
app.js
moment.js
moment-timezone.js
angular-moment.js

and some more - same error all the time.

Uncaught SyntaxError: Unexpected reserved word
moment-timezone.js:22 Uncaught TypeError: Cannot read property 'tz' of undefined(anonymous function) @ moment-timezone.js:22VERSION @ moment-timezone.js:16(anonymous function) @ moment-timezone.js:18
angular.js:11655 TypeError: Cannot read property 'utc' of undefined

using it in my template and created at is a timestamp 1400054171:

{{ driverslog.created_at | amDateFormat:'dddd, MMMM Do YYYY, h:mm'}}

@faouzioudouh
Copy link

@nikolai-b Thanks. i put moment.js before Angular and works like a charm.

@mariowise
Copy link

I solve my problem with this versions

"moment": "~2.11.2",
"angular-moment": "1.0.0-beta.4",

@realrogerrt
Copy link

realrogerrt commented May 9, 2016

I solved mine loading also the localization files bower_components/momentjs/min/moment-with-langs.min.js

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests