angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.8k stars 27.49k forks source link

Angularjs throws “Unexpected strict mode reserved word” which causes application to crash #7969

Closed sebastianzillessen closed 8 years ago

sebastianzillessen commented 10 years ago

I am currently developing an application for mobile phones using angularJS and cordova 3.2.

Some of my players report, that the application is not starting on their devices. This devices are listed below.

So it seems somehow connected to that Android Version 4.0.3/4.

Not starting means, that the cordova application is starting, but that angularjs crashes before it is initiated, because all the elements where an ng-cloak class is attached (which in my case is set for the complete root window) remain hidden. So the user does not see anything.

The problem is, that I don't have any of this devices to test it, but one player did send me the logs of his device, saying

Uncaught SyntaxError: Unexpected strict mode reserved word

With the line number and the file name I could determine, that the problem is caused by the code below (its from the angular.js v1.2.16 file in line 3878). The problem seems to apply in the statement throw err;

(#3878)
function createInternalInjector(cache, factory) {

  function getService(serviceName) {
    if (cache.hasOwnProperty(serviceName)) {
      if (cache[serviceName] === INSTANTIATING) {
        throw $injectorMinErr('cdep', 'Circular dependency found: {0}', path.join(' <- '));
      }
      return cache[serviceName];
    } else {
      try {
        path.unshift(serviceName);
        cache[serviceName] = INSTANTIATING;
        return cache[serviceName] = factory(serviceName);
      } catch (err) {
        if (cache[serviceName] === INSTANTIATING) {
          delete cache[serviceName];
        }
        throw err; /*** THE ERROR APPLIES HERE! **/
      } finally {
        path.shift();
      }
    }
  }

I cannot really say, what happens here. The applications works fine on other devices and other android versions.

Has anyone of you an idea how I could fix that issue for the players?

(I duplicated this issue from StackOverflow. )

sebastianzillessen commented 10 years ago

Any ideas here?

borhub commented 10 years ago

For us this was fixed by removing 'use strict'; from the very top of our app.js, as well as from the config argument function.

Like this:

// 'use strict'; // this was causing a whitescreen app hang on start due to syntax error "Unexpected strict mode reserved word" in angular's annotate()
                 // on some builds of Android 4.0.x (e.g. stock 4.0.4 Samsung GS2, but not GS3) in the APK version
                 // (and also m.site when run in dev mode, i.e. non-minified, in the Stock Browser) http://stackoverflow.com/questions/24370380/

var MYAPP = angular.module('SEEK', ['ui.router', 'ngResource', 'ngSanitize', 'ngAnimate', 'ngCookies', 'delegator', 'feature-flags', 'trackJs']);

MYAPP.config(function ($provide, $stateProvider, $urlRouterProvider, $locationProvider, $httpProvider, routeRule, DelegatorProvider, TrackJsProvider) {
    /* jshint strict: false */
    // Can't use 'use strict'; here either. See note above.

We're on AngularJS v1.2.13

lgalfaso commented 9 years ago

I am shooting darts in dark here, but can it be related to https://github.com/angular/angular.js/pull/7768 ?

Narretz commented 8 years ago

Long time no activity. I assume it's resolved.