Tutorial hero
Lesson icon

Issue in Sencha Cmd for Singleton Classes in Production and Package Builds

Originally published September 25, 2014 Time 2 mins

Updating your applications to the latest tech is always a satisfying and refreshing feeling – but it often opens you up to those few bugs that inevitably slip through. This particular bug happens to be quite a stinker.

It’s not uncommon to include a Utility file as a singleton class in your application to provide access to common functions throughout the app – I’ve written about this in the past. I also heavily rely on a singleton class for Facebook functionality in my soon to be released eBook, Build a Sencha Touch Login System.

When I built my application after upgrading to Sencha Cmd 5.0.2.270 and Sencha Touch 2.4.0 I was surprised to see an error I wasn’t previously getting:

Uncaught TypeError: Cannot read property 'showActiveItem' of undefined

showActiveItem is a function in my Utility class to help switch views. The surprising thing was that everything was working fine before building, and in a testing build, but not a production or package build.

It turns out this is a bug in Sencha Cmd and you can view the bug report here. Hopefully this is fixed soon but in the mean time there is a work around.

Working around the Sencha Cmd Singleton Bug

  • Open up the production.defaults.properties file in your .sencha folder within your project. This folder may be hidden. It is located at .sencha/app/production.defaults.properties. You will find the following options:
build.options.logger=no

build.options.debug=false

enable.deltas=true

enable.cache.manifest=true

enable.resource.compression=true

app.microloader.name=production.js

build.embedded.microloader.compressor=-closure

# enable the full class system optimizer
app.output.js.optimize=true
build.optimize=${build.optimize.enable}
  • Comment out the last line:
# enable the full class system optimizer
app.output.js.optimize=true
#UNCOMMENT FOLLOWING LINE AFTER FIX
#build.optimize=${build.optimize.enable}
  • Now rebuild your application and your singleton classes should work again
Learn to build modern Angular apps with my course