require statement not working properly with Titanium SDK 8.0.0.GA

155 views Asked by At

I have a classic titanium app, for some reason the require statement is not working properly

For example:

require("views/Player");

The required file is supposed to modify a global variable, but after requiring it the global variable is not modified.

The weirdest thing that it works fine when compiling against Ti SDK 7.4.2.GA and doesn't work when compiling against any newer version.

Can anyone explain this?

1

There are 1 answers

2
Mo Elsifi On BEST ANSWER

Okay, it turned out that prior to SDK 7.5.0, the app.js would assign any top-level variables to the global object. But not after that.

To fix it, you should declare global variables like this

global.labelText = 'Titanium Doesn't Rock!';

instead of this

var labelText = 'Titanium Doesn't Rock!';

More info here: https://docs.appcelerator.com/platform/latest/#!/guide/Titanium_SDK_7.5.0_Functionality_Update