[TIMOB-4826] module.exports not supported when requiring a file
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-11-10T14:18:40.000+0000 |
Affected Version/s | Release 1.7.2 |
Fix Version/s | Release 1.8.0.1 |
Components | iOS |
Labels | n/a |
Reporter | Rick Blalock |
Assignee | Blain Hamon |
Created | 2011-07-28T19:20:43.000+0000 |
Updated | 2011-12-07T16:01:57.000+0000 |
Description
module.exports is not supported in our require implementation.
module
is undefined.
FYI, module.exports is not part of CommonJS. It is supported by Node's implementation of modules, and perhaps by a few other implementations (not Rhino, for example). The CommonJS [module spec](http://wiki.commonjs.org/wiki/Modules/1.1.1) explicitly states "modules must use the "exports" object as the *only* means of exporting." They're speaking there of the "free variable"
exports
, notmodule.exports
. This suggests that using something calledmodule.exports
to export your API is, in fact, "illegal". :) NodeJS does it anyway. In the spec's discussion of themodule
variable, no reference to anexports
property is ever made. (For more of my long-winded arguments, see TIMOB-5406 :) ) [This discussion](http://groups.google.com/group/commonjs/browse_thread/thread/f994b609460355e3) on the official commonjs mailing list makes it clear that it's a Node thing and that the CommonJS spec folks are by no means unanimous in wanting to adopt it. I'm not opposed to supporting it, btw. Just want to make it clear it's not part of the spec and that it will need to be done with parity in mind, because Android uses Rhino's implementation of require() and it is *not* supported therein.http://wiki.commonjs.org/wiki/Modules/1.1#Related_Discussion
Hours recorded on 4825. Pull pending. https://github.com/appcelerator/titanium_mobile/pull/647
Closing bug. Verified fix on KS > Platform > Common JS using the following environment: OS: Mac OS X Lion Titanium Studio, build: 1.0.7.201112061404 SDK build: 1.8.0.1.v20111207151125 Device: iphone 4S Sprint (5.0.1)