Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20487] Extra properties after requiring commonjs modules

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2019-10-01T17:43:50.000+0000
Affected Version/sRelease 8.2.0, Release 8.1.1
Fix Version/sRelease 8.2.1
Componentsn/a
LabelscommonJS, engSchedule, ios, require
ReporterBrenton House
AssigneeChristopher Williams
Created2016-02-19T23:01:20.000+0000
Updated2019-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?

Comments

  1. Stephen Feather 2016-02-20

    From the commonJS module 1.1 specs: id is required
       The "module" object must have a read-only, don't delete "id" property that is the top-level "id" of the module. 
       The "id" property must be such that require(module.id) will return the exports object from which the module.id originated. 
       (That is to say module.id can be passed to another module, and requiring that must return the original module
       
    uri is optional
       The "module" object may have a "uri" String that is the fully-qualified URI to the resource from which the module was created. 
       The "uri" property must not exist in a sandbox.
       
    I expect id to exist.
  2. Sharif AbuDarda 2016-02-24

    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.
  3. Brenton House 2016-02-24

    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)
  4. Brenton House 2016-02-25

    [~sdarda] - Why is this marked as fixed? I don't see any commits or activity that would indicate it was worked on.
  5. Brenton House 2017-06-05

    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!
  6. Brenton House 2019-09-14

    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:
       test1: {
         "id": "abc",
         "firstName": "my first name",
         "lastName": "my last name"
       }
       
       
    But in Titanium, it will give you the incorrect output of:
        test1: {
         "id": "node_modules/@brentonhouse/timob-20487/test1.js",
         "firstName": "my first name",
         "lastName": "my last name",
        "uri": "app://node_modules/@brentonhouse/timob-20487/test1.js"
        } 
       
  7. Brenton House 2019-09-16

    PR: https://github.com/appcelerator/titanium_mobile/pull/10929
  8. Satyam Sekhri 2019-09-23

    Kindly create PR on the 8_2_X branch as well.
  9. Lokesh Choudhary 2019-10-01

    [~ssekhri], 8_2_X backport : https://github.com/appcelerator/titanium_mobile/pull/11250
  10. Satyam Sekhri 2019-10-01

    FR Passed on both 8_2_X and master branch. Appropriate fields available for the required common js module.
  11. Satyam Sekhri 2019-10-01

    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)

JSON Source