Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24373] npm node_modules are erroring out during build

GitHub Issuen/a
TypeBug
PriorityNone
StatusResolved
ResolutionDuplicate
Resolution Date2018-08-13T07:37:32.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelscb-tooling
ReporterFeon Sua Xin Miao
AssigneeUnknown
Created2017-02-04T03:57:50.000+0000
Updated2018-08-13T07:37:33.000+0000

Description

*Reproduce Steps* 1. Create a ti classic app 2. Create a package.json file under Resources folder:
{
  "name": "myapp",
  "description": "myapp",
  "private": true,
  "dependencies": {
  },
  "devDependencies": {
    "mocha": "2.5.3",
    "should": "7.1.1",
    "ti-mocha": "0.2.0"
  }
}
3. Run npm install under Resources folder 4. Build the project *Expected Result* The app builds without error *Actual Result*
[ERROR] Failed to parse /Users/feonsua/work/apps/test/Resources/node_modules/mocha/node_modules/glob/test/00-setup.js
[ERROR] SyntaxError: 'return' outside of function [line 82, column 0]
[ERROR]   
[ERROR]     }
[ERROR]   

Comments

  1. Chris Barber 2017-02-17

    Well, we don't have a lot of options. We either A) gut the entire catch clause and completely ignore any parse errors, or B) replace the this.logger.error with this.logger.warn and remove the process.exit(1).
       try {
       	// parse the AST
       	var r = jsanalyze.analyzeJsFile(from, { minify: this.minifyJS });
       } catch (ex) {
       	ex.message.split('\n').forEach(this.logger.error);
       	this.logger.log();
       	process.exit(1);
       }
       
    https://github.com/appcelerator/titanium_mobile/blob/master/iphone/cli/commands/_build.js#L5642-L5649 We AST parse all .js files using Uglify to find all Titanium APIs that are used so we can enable only the modules that are needed. The second we trying parsing a .js file that Uglify doesn't like or understand, the build fails. This is actually a much bigger problem than some bad .js syntax. The version of Uglify that we use is pretty old and doesn't support the latest ECMAScript standards. This means valid syntax will cause builds to fail. The next major Titanium build architecture will use Babylon, which is fantastic and allows plugins that will adapt to new standard changes. Unfortunately, we can't just rip out Uglify and drop in Babylon. It's going to be a significant amount of work.
  2. Brenton House 2017-04-10

    As a workaround for anyone dealing with this issue, you can use nativeloop https://github.com/nativeloop/nativeloop. Basically, nativeloop looks for every call to uglifyjs.parse and make sure to run babeljs before those calls. This ensures that the code is downgraded to an es5 format before uglifyjs tries to parse it.
  3. Hans Knöchel 2018-08-13

    Duplicate of ALOY-1540, fixed in Alloy 1.9.11+

JSON Source