[TIMOB-20487] Extra properties after requiring commonjs modules
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-10-01T17:43:50.000+0000 |
Affected Version/s | Release 8.2.0, Release 8.1.1 |
Fix Version/s | Release 8.2.1 |
Components | n/a |
Labels | commonJS, engSchedule, ios, require |
Reporter | Brenton House |
Assignee | Christopher Williams |
Created | 2016-02-19T23:01:20.000+0000 |
Updated | 2019-10-01T17:43:50.000+0000 |
Description
I've run into an issue that only shows up when I am deploying to iOS hardware w/o liveview.
var x = require("some_commonjs_module");
If I run this code w/ liveview turned on, the only properties of x are the ones that are in the module. However, if I run this without liveview (hardware or simulator), I get two extra properties: id and uri.
This is causing an issue because I am using _.defaults and now it thinks I have those properties that I expected to be undefined.
Is this a known feature/bug of require or a new issue?
From the commonJS module 1.1 specs: id is required
uri is optional
I expect id to exist.
Hello [~brentonhouse], Was the guide from [~sfeather] helpful? If you are still facing the problem, Would you please provide full steps of how to regenerate the issue. Please provide the necessary code, platform information and steps to follow. Thanks. Also here is [CommonJS wiki](http://wiki.commonjs.org/wiki/Modules/1.1.1). Thanks.
Thanks [~sfeather]! I may be misunderstanding the spec but I thought that the id and uri properties were on module, not on module.exports? I was under the assumption that the id and uri properties were at the same level as exports (i.e. module.id, module.uri, module.exports)
[~sdarda] - Why is this marked as fixed? I don't see any commits or activity that would indicate it was worked on.
Any update on this? I also notice that you are exporting the uri property as well (which will overwrite any exported property named uri). I think the priority of this might need to get bumped up with the recent emphasis on making everything more compatible with the nodejs module exports. Maybe you could change the properties to __uri and __id so as to remove possible conflicts with exported properties. Thanks!
I've created a test project to demonstrate this: 1. npm install @brentonhouse/timob-20487 2. put this code in a node.js javascript file and and alloy.js: require('timob-20487'); In Node.js it will give you the correct output of:
But in Titanium, it will give you the incorrect output of:
PR: https://github.com/appcelerator/titanium_mobile/pull/10929
Kindly create PR on the 8_2_X branch as well.
[~ssekhri], 8_2_X backport : https://github.com/appcelerator/titanium_mobile/pull/11250
FR Passed on both 8_2_X and master branch. Appropriate fields available for the required common js module.
Verified On: Mac OS: 10.14.5 SDK: 8.2.1.v20191001063013 Appc CLI: 7.1.1 JDK: 1.8.0_162 Node: 10.5.0 Studio: 5.1.4.201909061933 Xcode: 11.0 Device: iPhone X(13.0)