Appcelerator and Node.js

Appcelerator and Node.js

I hadn’t build an app in Titanium lately because I had been focusing on some other projects that were Xojo based. Some time had passed and I hadn’t even opened the IDE. Then a project came a long and I needed to pull out Appcellerator again and dust it off. I opened up a project where I had left it off. There was an update to Titanium to install – did that – cracked open my project and initiated a build to the iphone simulator – and ran into the following error:

/usr/local/lib/node_modules/titanium/node_modules/longjohn/dist/longjohn.js:181 throw e;

The app wouldn’t build – the command line tools would not work – total chaos.

…turns out I had updated my Node.js installation for another project I was working on and Titanium did not like it. They prefer you use something in the 0.8.x family and I was at 0.11.4 so this was definitely not going to work. Luckily, there are already two very cool utility which make managing which version of node you are using really easy: n and nvm.

I personally prefer n but nvm worked better in this case because my preferred shell is tcsh but Titanium’s is bash… nvm works great in bash, and for Titanium.

Solution

So – in a nutshell – the solution is install nvm, install Node.js v0.8.25 using nvm, make it the default node version and THEN run Titanium. Voila – back to normal!

Something like this under bash:

#get nvm
curl https://raw.github.com/creationix/nvm/master/install.sh | sh

#get an older node version
nvm install 0.8.25

#use the new old version and set it as default
nvm use 0.8.25
nvm alias default 0.8.25

#check
node -v

#should say 'v0.8.25'

Caveat

Since my default shell and Titanium’s default shell were different, it took some extra steps for me to sort it out, but the easiest way would have been to just access the terminal from within Titanium>Window>Show View>Terminal Editor and install nvm, etc from there. That way everything is exactly where Titanium can find it. I am on a mac BTW.

I’m posting this just in case anyone else is running into it. If you found it helpful in any way, please let me know.