Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23381] Parity: Titanium CommonJS modules require'd differently than NodeJS require spec

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-06-10T08:09:15.000+0000
Affected Version/sRelease 5.3.0
Fix Version/sRelease 6.0.0
ComponentsAndroid, iOS
Labelsn/a
ReporterChristopher Williams
AssigneeChristopher Williams
Created2016-05-16T16:57:54.000+0000
Updated2018-11-16T15:41:04.000+0000

Description

We have a long-standing issue with how Titanium CommonJS modules are require'd. One would assume they'd follow typical NodeJS conventions with requires, so when you do:
require('module.id');
I would expect that it should attempt to load up modules/commonjs/module.id/<version> as a directory as per TIMOB-23382 Instead, our Android and iOS implementation looks for modules/commonjs/module.id/<version>/module.id.js, and ignore any package.json, index.js, or index.json in that directory.

Comments

  1. Chee Kiat Ng 2016-06-10

  2. Brenton House 2016-07-19

    [~cwilliams] [~cng] How will this handle widgets that have other npm dependencies? Currently, if a widget has dependencies in the npm package, Alloy doesn't include the node_modules folder. Should I create a ticket for this or is this going to be handled by the new nodejs module resolution that [~cwilliams] has been working on? Thanks!
  3. Christopher Williams 2016-07-19

    [~brentonhouse] This shouldn't really affect widgets in any particular way, so if there's a bug now, please file it. This basically changes Titanium commonjs modules to not be a single JS files, but an entire directory that will get packaged into the app - and you can now use package.json/index.js/index.json, and not have to ensure you have all your JS crammed into a single file whose name matches the module id.
  4. Brenton House 2016-07-19

    Currently widgets can be distributed via npm (http://www.appcelerator.com/blog/2016/05/distributing-alloy-widgets-via-npm/). Say my widget has a dependency on lodash. If I use the nodejs way of doing things and make it a dependency, it installs it to the node_modules folder of the widget, but when Alloy imports the widget at compile-time, it doesn't bring in the node_modules folder.
  5. Lokesh Choudhary 2016-08-15

    Verified the fix. Used the same test code in TIMOB-23382. Closing. Environment: Appc Studio : 4.7.0.201607250649 Ti SDK : 6.0.0.v20160814220332 Ti CLI : 5.0.9 Alloy : 1.9.1 MAC El Capitan : 10.11.6 Appc NPM : 4.2.7 Appc CLI : 6.0.0-24 Node: 4.4.4 Nexus 6 - Android 6.0.1 iOS simulator: Iphone 6s 9.3

JSON Source