Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23997] iOS and Android revert incorrect CommonJS module changes

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2016-12-05T18:04:46.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.1.0
ComponentsTooling
Labelscb-tooling
ReporterChris Barber
AssigneeChristopher Williams
Created2016-10-07T06:18:43.000+0000
Updated2017-07-19T15:21:27.000+0000

Description

Both the Android and iOS build have a bug when resolving the main JS file in a CommonJS Titanium module. Normally the JS files are named <module id>.js, but if this doesn't exist, it should: * See if there's a package.json * If there is, read it in and find a main property * Check that the file defined by main actually exists * If exists, use it * If not exists, look for an index.js file As apart of TIMOB-23382 (PR https://github.com/appcelerator/titanium_mobile/pull/8004), the logic is bad. It will set the module.libFile to package.json or index.json which is technically incorrect. The good news is module.libFile for CommonJS modules is not used anywhere, however we should still fix it.

Attachments

FileDateSize
modules.zip2016-10-11T20:22:12.000+000014995
timob23997BuildLog.rtf2016-12-05T19:50:53.000+000029438

Comments

  1. Chris Barber 2016-10-11

    TiSDK master PR: https://github.com/appcelerator/titanium_mobile/pull/8500 To test, add the following to your tiapp.xml:
       <modules>
       	<module>foo</module> <!-- foo.js -->
       	<module>foo-main</module> <!-- bar.js -->
       	<module>foo-main-noext</module> <!-- bar -->
       	<module>foo-main-rel</module> <!-- ./bar -->
       	<module>foo-main-rel-subdir</module> <!-- lib/bar -->
       	<module>foo-index</module> <!-- index.js -->
       	<module>foo-bad-nofile</module>
       </modules>
       
    Then unzip the attached modules.zip file into your project directory and build the app for both iOS and Android. You should see something like the following:
       [DEBUG] Detected commonjs module: com.appc.foo 1.0.0 @ /Users/chris/appc/workspace/testapp/modules/commonjs/foo/1.0.0
       [DEBUG] Detected commonjs module: com.appc.foo 1.0.0 @ /Users/chris/appc/workspace/testapp/modules/commonjs/foo-bad-nofile/1.0.0
       [DEBUG] Detected commonjs module: com.appc.foo 1.0.0 @ /Users/chris/appc/workspace/testapp/modules/commonjs/foo-index/1.0.0
       [DEBUG] Detected commonjs module: com.appc.foo 1.0.0 @ /Users/chris/appc/workspace/testapp/modules/commonjs/foo-main/1.0.0
       [DEBUG] Detected commonjs module: com.appc.foo 1.0.0 @ /Users/chris/appc/workspace/testapp/modules/commonjs/foo-main-noext/1.0.0
       [DEBUG] Detected commonjs module: com.appc.foo 1.0.0 @ /Users/chris/appc/workspace/testapp/modules/commonjs/foo-main-rel/1.0.0
       [DEBUG] Detected commonjs module: com.appc.foo 1.0.0 @ /Users/chris/appc/workspace/testapp/modules/commonjs/foo-main-rel-subdir/1.0.0
       <snip>
       [DEBUG] Looking for Titanium module id=foo version=latest platform=android,commonjs deploy-type=development
       [INFO]  Found Titanium module id=foo version=1.0.0 platform=commonjs deploy-type=development path=/Users/chris/appc/workspace/testapp/modules/commonjs/foo/1.0.0
       [DEBUG] Looking for Titanium module id=foo-main version=latest platform=android,commonjs deploy-type=development
       [INFO]  Found Titanium module id=foo-main version=1.0.0 platform=commonjs deploy-type=development path=/Users/chris/appc/workspace/testapp/modules/commonjs/foo-main/1.0.0
       [DEBUG] Looking for Titanium module id=foo-main-noext version=latest platform=android,commonjs deploy-type=development
       [INFO]  Found Titanium module id=foo-main-noext version=1.0.0 platform=commonjs deploy-type=development path=/Users/chris/appc/workspace/testapp/modules/commonjs/foo-main-noext/1.0.0
       [DEBUG] Looking for Titanium module id=foo-main-rel version=latest platform=android,commonjs deploy-type=development
       [INFO]  Found Titanium module id=foo-main-rel version=1.0.0 platform=commonjs deploy-type=development path=/Users/chris/appc/workspace/testapp/modules/commonjs/foo-main-rel/1.0.0
       [DEBUG] Looking for Titanium module id=foo-main-rel-subdir version=latest platform=android,commonjs deploy-type=development
       [INFO]  Found Titanium module id=foo-main-rel-subdir version=1.0.0 platform=commonjs deploy-type=development path=/Users/chris/appc/workspace/testapp/modules/commonjs/foo-main-rel-subdir/1.0.0
       [DEBUG] Looking for Titanium module id=foo-index version=latest platform=android,commonjs deploy-type=development
       [INFO]  Found Titanium module id=foo-index version=1.0.0 platform=commonjs deploy-type=development path=/Users/chris/appc/workspace/testapp/modules/commonjs/foo-index/1.0.0
       [DEBUG] Looking for Titanium module id=foo-bad-nofile version=latest platform=android,commonjs deploy-type=development
       [INFO]  Found Titanium module id=foo-bad-nofile version=1.0.0 platform=commonjs deploy-type=development path=/Users/chris/appc/workspace/testapp/modules/commonjs/foo-bad-nofile/1.0.0
       [ERROR] Module "foo-bad-nofile" v1.0.0 is missing main file: foo-bad-nofile.js, package.json with "main" entry, or index.js
       
  2. Chris Barber 2016-11-03

    I reverted all changes to the build with respect to CommonJS modules in the Android and IOS build. TiSDK master PR: https://github.com/appcelerator/titanium_mobile/pull/8500 TiSDK 6_0_X PR: https://github.com/appcelerator/titanium_mobile/pull/8623
  3. Christopher Williams 2016-12-01

    The PRs here have broken functionality for us to support commonJS modules that don't have a file named the exact same as the module id inside.
  4. Christopher Williams 2016-12-01

    https://github.com/appcelerator/titanium_mobile/pull/8649 https://github.com/appcelerator/titanium_mobile/pull/8648
  5. Abir Mukherjee 2016-12-05

    I tested with this environment: NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.12.1 Appc CLI: 6.0.0 Appc CLI NPM: 4.2.8 Titanium SDK version: 6.0.1.v20161202124626 Appcelerator Studio, build: 4.8.0.201611121409 Xcode 8.1 GM I did get the messages that the modules were found. However, I also got this message for each module when I tried to build it on either Android or iOS device:
       [DEBUG] Module foo requires Titanium SDK 6.1.0 or newer, but the selected SDK is 6.0.1
       [WARN]  Could not find a valid Titanium module id=foo version=latest platform=ios,iphone,commonjs deploy-type=development
       
       [ERROR] Could not find all required Titanium Modules:
       [ERROR]    id: foo	 version: latest	 platform: ios,iphone,commonjs	 deploy-type: development
       
    The log is attached. [^timob23997BuildLog.rtf]
  6. Abir Mukherjee 2016-12-09

    NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.12.1 Appc CLI: 6.0.0 Appc CLI NPM: 4.2.8 Titanium SDK version: 6.1.0.v20161205110006 Appcelerator Studio, build: 4.8.0.201611121409 Xcode 8.1 GM Fix is validated. Note that fix was validated using the attached zip, which has a min SDK 6.1.0
  7. Alberto Marcone 2017-07-19

    since the update to 6.1.0, the app freezes on startup on a real device (everything works fine on the simulator). The app is pre-alloy, so everything is in CommonJS. The error I get: [ERROR] Application received error: undefined is not a constructor (evaluating 'new(void 0)') at downloader.js (line 1) [ERROR] Application received error: Module "module/controllers/loginController.js" failed to leave a valid exports object The only thing I can think of, is that inside downloader.js there's this kind of code: --- var downloader = function() { var myModule = require('com.myNativeModule'); var downloadUtility = require("/module/helpers/download_utility"); [.....] } module.exports = downloader; ---
  8. Alberto Marcone 2017-07-19

    not sure if the error is related to this ticket, I went through all of the fixes/new features and this looked something that could interfere with CommonJS and modules. In case I will open a new ticket.

JSON Source