Skip to content
This repository

Fix for moment not working under browserify #25

Merged
merged 1 commit into from over 2 years ago

2 participants

Steve Mason Tim Wood
Steve Mason

Small fix to the NodeJS detection to make the module work when run client-side using browserify.

I think the way underscore does its client/server-side check best, but didn't want to make that big a change.

Tim Wood
Owner

Sorry, I'm not super familiar with browserify. I'll read up on it today, but maybe you know the answer to the question.

Will this have to change the way Moment.js loads languages?

Currently, Moment.js require()s language files relative to the moment.js source based on keys passed in. Will browserify be able to handle this, or does it require a bigger fix?

https://github.com/timrwood/moment/blob/master/moment.js#L332

Steve Mason

Hi Tim,

At the moment browserify generates a warning when it sees the language require's and I think it does nothing about it - I'm not worried because I'm not using that functionality.

It should be safe to ignore the warning - browserify people can always load the languages manually (if I understand the code). Maybe browserify has a way of letting you tell it about these modules, but I'm not sure.

Tim Wood timrwood merged commit ef1d150 into from October 18, 2011
Tim Wood timrwood closed this October 18, 2011
Tim Wood
Owner

Ok, sounds good. If people need browserify and moment.lang, they will have to require the lang files manually using browserify.

Tim Wood
Owner

This is up on npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 18, 2011
Steve Mason Fix for moment not working under browserify, because "window" is defi…
…ned here
1299b72
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. 2  moment.js
2  moment.js
@@ -10,7 +10,7 @@
10 10
     var moment,
11 11
         round = Math.round,
12 12
         languages = {},
13  
-        isNode = (typeof window === 'undefined' && typeof module !== 'undefined'),
  13
+        isNode = (typeof module !== 'undefined'),
14 14
         paramsToParse = 'months|monthsShort|weekdays|weekdaysShort|relativeTime|ordinal'.split('|'),
15 15
         i,
16 16
         shortcuts = 'Month|Date|Hours|Minutes|Seconds'.split('|');
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.