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

Moment is undefined #79

Closed
szantner opened this issue Sep 11, 2014 · 11 comments
Closed

Moment is undefined #79

szantner opened this issue Sep 11, 2014 · 11 comments

Comments

@szantner
Copy link

Using angularjs, node-webkit and angular-moment together I always got errors related to moment being undefined.

As I changed

.constant('moment', moment)

to

.constant('moment', (typeof global !== 'undefined' ? global : this).moment)

in angular-moment.js it stopped to complain. I don't know if it makes any problem in other environments though.

@JulienO
Copy link

JulienO commented Sep 11, 2014

I have the same problem but your solution does not work for me .. Using Angularjs/Ionic

@ragn
Copy link

ragn commented Sep 12, 2014

It's a "problem" with moment.js according to this issue. The workaround mentioned there worked for me.

@szantner
Copy link
Author

The thing is if I don't put moment.js in bower.json and use it via that then angular-moment has a broken dependency when checking bower list, which is not too nice also. Actually moment-timezone has the same issue with it: moment/moment-timezone#128

@mattvv
Copy link

mattvv commented Dec 9, 2014

I ran into this issue in atom-shell (similar to node-webkit). I fixed it with the following fix and adding moment to my local npm file, this way moment is used locally.

@urish
Copy link
Owner

urish commented Dec 10, 2014

Should be resolved by #95. If there are still issues, please re-open (or even better - send a PR).

@kitbrennan90
Copy link
Contributor

This still isn't fixed. I have submitted a pull request: #133

@iCoolchar
Copy link

I also get the issue. I run:
npm install moment
var moment = require("moment");

but when I webpack it and open the browser, it said :
Uncaught ReferenceError: moment is not defined

Any one can help? Thanks!

@patribezek
Copy link

I have the same issue, the solution doesn't work in my project

@vanhumbeecka
Copy link

I solved it for my project. The issue is related to Webpack, and is similar to an issue where the jQuery global is not being found.
When using webpack, and you need to define some globals, don't use the es6 import statement, but use the following syntax

window.jQuery = window.$ = require('../../node_modules/jquery/dist/jquery.min');
window.moment = require('moment');

@smichaud
Copy link

smichaud commented Nov 9, 2017

@vanhumbeecka Thank you for your reply. Not very clean, but it solves my problem. Here what I did:
import moment from 'moment/moment'; window.moment = moment;

@ghost
Copy link

ghost commented Jan 7, 2019

@vanhumbeecka that works for me, thank you.

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

10 participants