Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasModule check fails if require is not defined #1537

Closed
iby opened this issue Mar 18, 2014 · 9 comments
Closed

hasModule check fails if require is not defined #1537

iby opened this issue Mar 18, 2014 · 9 comments

Comments

@iby
Copy link

iby commented Mar 18, 2014

I'm using webpack to build the bundle and after recent update moment.js gets incorrectly included into the module. Here is the full story: webpack/webpack#204 (comment).

This happens because it tries to check if the require is defined, I'm assuming this was done with a reason, but is it still valid these days?

hasModule = (typeof module !== 'undefined' && module.exports && typeof require !== 'undefined'),

Ideally this should be like this:

hasModule = typeof module !== 'undefined' && module.exports,

Or if the require check is beneficial for some reason, then perhaps like this:

hasModule = (typeof module !== 'undefined' && module.exports) || typeof require !== 'undefined',
@icambron
Copy link
Member

The check for require was introduced in #1238 for QUnit, which I guess defines module and module.exports without defining require and for whatever we wanted to avoid using module.exports with it and just export moment as a global. I don't know enough about QUnit to know for sure, but I suspect the QUnit user simply shouldn't be using the global, and that they were simply working around its quasi-module implementation. So I'd be up for reverting that if @ichernev agrees.

@iby
Copy link
Author

iby commented Mar 19, 2014

Does mr. @ichernev agree?

@ichernev
Copy link
Contributor

ichernev commented Apr 2, 2014

@jgerigmeyer do you know why in qunit tests moment is used as a browser global. Also does QUnit have module.exports?
@icambron @ianbytchek I think what you say makes sense, but as you may imagine the js ecosystem is diverse enough so that any change would break somebody's workflow :)

So QUnit defines module and module.exports but is not CommonJS. For module -- ok, but why module.exports. I can not find this in the docs / source code.

@jgerigmeyer
Copy link
Contributor

At the time I was using moment in a non-CommonJS/RequireJS project, and testing custom language settings via QUnit tests, which is why I was accessing moment as a browser global. (I've since decided unit tests don't need to test actual moment functionality, so I'm no longer doing this.)

QUnit itself does not define module.exports. This was a bug in an earlier version of sinon.js (see sinonjs/sinon#333).

In short, I agree that #1238 should probably be reverted.

I'm sure I'm being slow, but why is accessing moment via a browser global being discouraged?

@icambron
Copy link
Member

icambron commented Apr 3, 2014

It's not being discouraged in general. It's being discouraged in the presence of module, since that results in mucking with node global scope.

@jgerigmeyer
Copy link
Contributor

Ah yes, I see that now. Makes perfect sense, #1238 should be reverted, and I apologize for not discovering the sinon.js bug before submitting that pull request 5 months ago.

ichernev added a commit to ichernev/moment that referenced this issue Apr 3, 2014
…g when using with QUnit)."

This reverts commit ed6a2d4.
This was discussed in moment#1537 (comment)
@jzaefferer
Copy link

For the record, Qunit exports itself to module.exports since 1.13.0.

There has been an attempt to extend exports for more environments, but that isn't really going anywhere.

@ichernev
Copy link
Contributor

ichernev commented Apr 4, 2014

Well we started from UMD (not really) and then patched it until every hostile environment and use case is supported. The state of the js module systems is just sad, very sad.

@icambron
Copy link
Member

icambron commented Apr 4, 2014

Closed by #1588

@icambron icambron closed this as completed Apr 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants