I am trying to use Javascript code originally designed for a NodeJS environment in Titanium. They make use of the console.log method, which was introduced in Titanium SDK 2.1.0 to make porting from other environments easier. On iPhone, console.log works fine. It also kind of works on Android, but only when called from app.js or a file included from app.js via Titanium.include. It never works on Android from within a CommonJS module file. I always get the following error: "Uncaught ReferenceError: console is not defined."
For example:
app.js:
console.log('inside app.js'); Ti.include('include.js'); require('require');include.js:
console.log('inside include.js');require.js:
console.log('inside require.js');On iPhone, all three messages are logged. However, on Android, only the first two ("inside app.js" and "inside include.js") are logged and it crashes on the first line of require.js:
console.log('inside require.js');
Any suggestions would be appreciated. I know that I could use Titanium.API.log instead, but that is not very attractive as it would require a giant find and replace and console.log is supposed to work!
- Application type: mobile
- Titanium SDK: 2.1.1 (07/27/12 14:01 0fd84a2)
- Platform and version: Android 2.2
- Device: Android emulator
- Host Operating System: OSX 10.7.4
- Titanium Studio: 2.1.1.201207271312
1 Answer
Probably a Bug, you could work around
console = console || {}; console.log = console.log || function(s) { Ti.API.info(s);or some thing similar
Your Answer
Think you can help? Login to answer this question!