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 #194

Closed
ColonelBundy opened this issue Nov 7, 2015 · 30 comments
Closed

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

ColonelBundy opened this issue Nov 7, 2015 · 30 comments

Comments

@ColonelBundy
Copy link
Contributor

This is now fixed, It was a nw.js issue.
See: #196 For more details.

@urish
Copy link
Owner

urish commented Nov 7, 2015

Can you verify that moment is loaded into your page successfully?

Please try opening the chrome devtools and typing there moment, check what the it says...

Thx

@ColonelBundy
Copy link
Contributor Author

moment
\moment\moment.js:15 function utils_hooks__hooks() {
        return hookCallback.apply(null, arguments);
    }

First thing I did before creating this post :)

@urish
Copy link
Owner

urish commented Nov 7, 2015

thanks, are you using the latest version of angular-moment? that is 1.0.0-beta.2

@ColonelBundy
Copy link
Contributor Author

used bower to install so I guess yes?

Also checked top of the js file : /* angular-moment.js / v0.10.3 / (c) 2013, 2014, 2015 Uri Shaked / MIT Licence */

well I guess no now when I checked the repo compared to my js file.

@urish
Copy link
Owner

urish commented Nov 7, 2015

bower install does not currently pull the beta version, please try installing the beta by writing:

bower i -S angular-moment#1.0.0-beta.2

thanks!

@ColonelBundy
Copy link
Contributor Author

TypeError: undefined is not a function
    at preprocessDate (angular-moment.js:396)
    at updateMoment (angular-moment.js:251)
    at Object.fn (angular-moment.js:269)

Still..

@urish
Copy link
Owner

urish commented Nov 7, 2015

Can you put a breakpoint at angular-moment.js line 98 and see what the value of moment is there?

thx

@ColonelBundy
Copy link
Contributor Author

TypeError: undefined is not a function
    at angular.module.constant.constant.constant.directive.service.preprocessDate (VM1188 angular-moment.js:396)
    at updateMoment (VM1188 angular-moment.js:251)
    at Object.fn (VM1188 angular-moment.js:269)

@urish
Copy link
Owner

urish commented Nov 7, 2015

For some reason, moment is not defined when angular-moment is being loaded. Can't really tell you why it is happening without seeing the entire codebase, but if you could create a small sample that reproduces it I'd be able to look into it

@ColonelBundy
Copy link
Contributor Author

I can do that certainly, But I came to believe now it might be nw.js (formerly known as node-webkit) that is the culprit here?

EDIT: tried using npm and: var moment = require('moment'); still no dice.

@urish
Copy link
Owner

urish commented Nov 8, 2015

Actually yes, see #104

@ColonelBundy
Copy link
Contributor Author

I actually looked over that issue before I created this, and thought I post anyways. But as you can see even using node.js's require doesn't work.

@urish
Copy link
Owner

urish commented Nov 8, 2015

Can you try changing line 662 to read:

angularMoment(require('angular'), moment);

instead of

angularMoment(require('angular'), require('moment'));

and check if it fixes the issue ?

@ColonelBundy
Copy link
Contributor Author

same error still..

@urish
Copy link
Owner

urish commented Nov 8, 2015

Interesting... Are you using moment 2.10.3? Someone noted on #104 that upgrading to 2.10.3 helped solve a similar problem with nw.js

@ColonelBundy
Copy link
Contributor Author

I was using 2.10.6, downgraded to 2.10.3, still no dice.

@urish
Copy link
Owner

urish commented Nov 8, 2015

So both when using bower and npm, moment comes out undefined in the context of angular-moment?

@ColonelBundy
Copy link
Contributor Author

That's right.

@urish
Copy link
Owner

urish commented Nov 8, 2015

Okay, do you want to try debugging it and coming back with some conclusions why it happens? Alternatively, if you can create a small example that reproduces this behavior, I can look into it...

@ColonelBundy
Copy link
Contributor Author

Okay, kind of "solved" it...

var moment1 = require('moment');
.constant('moment', moment1)

But got a deprecation warning saying moment falls back to js Date and everything becomes "Invalid date."

@urish
Copy link
Owner

urish commented Nov 8, 2015

Do you get the warning when using $scope.date = new Date()?

The deprecation warnings appears when you pass moment a string instead of a Date object...

@ColonelBundy
Copy link
Contributor Author

Do you get the warning when using $scope.date = new Date()?

Yes.

The deprecation warnings appears when you pass moment a string instead of a Date object...

Yea I read about that @ the linked github issue.

@urish
Copy link
Owner

urish commented Nov 8, 2015

Seems like others are also facing similar issues, e.g. nwjs/nw.js#2075.

Very strange that the Date stuff doesn't work - can you please double-verify by logging the value which is passed to preprocessDate in line 396?

@ColonelBundy
Copy link
Contributor Author

It returns nothing, its blank. Thought I broke it at first but its just nothing... It no longer says invalid date though... but nothing gets returned.

@urish
Copy link
Owner

urish commented Nov 8, 2015

and what does it get (inside the value parameter, in line 396)?

does value instanceof Date evaluate true at that line?

Uri

@ColonelBundy
Copy link
Contributor Author

I feel embarrassed... Sorry for taking up your time on this latest issue of the new Date() thing... I accidentally closed down my powershell which had gulp watch running... Took me a while to figure out why the hell my js didnt update... Well I got the am-time-ago working in a ng-repeat a little while ago and I was stunned the new Date() thing didn't... So again I'm sorry..

However, Now when its working wonders I would like to give me two thanks for helping me with this, you've been really helpful! Not many people I know are being this helpful and actually taking the time to resolve it.

I would also like to add, If you could do a check for moment already before:

function angularMoment(angular, moment)

And then throw an error if you can't find it, Would make sense right? it would be really helpful for others. And also, document the solution I had to use to make it work for nw.js would also be helpful for others.

Again, thank you very much!

@urish
Copy link
Owner

urish commented Nov 8, 2015

No worries :)

Yes, I think that adding a check at the beginning of the function and throwing a more descriptive error if moment is undefined makes a lot of sense. If you have some time to create a PR for it, that will be awesome!

Uri

@ColonelBundy
Copy link
Contributor Author

PR submitted.

@urish
Copy link
Owner

urish commented Nov 8, 2015

great!

On Sun, Nov 8, 2015 at 3:23 AM, Marcus notifications@github.com wrote:

PR submitted.


Reply to this email directly or view it on GitHub
#194 (comment)
.

@urish
Copy link
Owner

urish commented Nov 8, 2015

Fixed by #196

@urish urish closed this as completed Nov 8, 2015
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

2 participants