[TIMOB-24373] npm node_modules are erroring out during build
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Resolved |
Resolution | Duplicate |
Resolution Date | 2018-08-13T07:37:32.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | cb-tooling |
Reporter | Feon Sua Xin Miao |
Assignee | Unknown |
Created | 2017-02-04T03:57:50.000+0000 |
Updated | 2018-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]
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 thethis.logger.error
withthis.logger.warn
and remove theprocess.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.
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.
Duplicate of ALOY-1540, fixed in Alloy 1.9.11+