Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24726] iOS: Error when requiring ES6 class

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2017-05-23T21:44:30.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsES6, Titanium
ReporterBrenton House
AssigneeChristopher Williams
Created2017-05-23T20:35:36.000+0000
Updated2017-05-23T21:44:30.000+0000

Description

When calling require('animal') I am getting the following error: {noformat} [ERROR] message = "Unexpected use of reserved word 'class'"; {noformat} animal.js
'use strict';

class Animal { 
	constructor(name) {
		this.name = name;
	}
	speak() {
		console.log(this.name + ' makes a noise.');
	}
}

module.exports = Animal;

Comments

  1. Sharif AbuDarda 2017-05-23

    Hello, Can you provide a full reproducible code and steps to generate the issue? Thanks.
  2. Brenton House 2017-05-23

    Steps to recreate: 1. Create new Titanium app using CLI 2. Create new file: lib/animal.js
       'use strict';
       
       class Animal { 
       	constructor(name) {
       		this.name = name;
       	}
       	speak() {
       		console.log(this.name + ' makes a noise.');
       	}
       }
       
       module.exports = Animal;
       
    3. Add the following line to controllers/index.js:
       require('animal');
       
    3. Run the app: appc ti build --platform ios --target simulator --log-level trace
  3. Christopher Williams 2017-05-23

    Is this at runtime? If so, it's because you need to switch to the bundled JSCore engine from iOS to get ES6 support. Our TiCore fork is very old. You do that by setting a special value in your tiapp.xml:
       <ti:app>
           <ios>
               <use-jscore-framework>true</use-jscore-framework>
           </ios>
       </ti:app>
       
    there's more details on the PR itself about this: https://github.com/appcelerator/titanium_mobile/pull/8972 But basically, we do not transpire your ES6 code down to ES5 on older engines (yet). We pass the code through and it's up the JS engine if it supports it. TiCore is very old and does not. Using bundled JSCore means it's up to the iOS version you're running (see https://kangax.github.io/compat-table/es6/)
  4. Brenton House 2017-05-23

    Sorry about that [~cwilliams]! Forgot to switch that on for the new project. You can close this ticket.

JSON Source