Alejandro Urbano Alvarez
Alejandro Urbano Alvarez

Reputation: 3346

Requiring external JavaScript file

After reading all the relevant answers in SO and posts in the Appcelerator forums I still can't get this to work:

I have an application developed in Appcelerator, and I want to load an external JavaScript file in some of my controllers.

My App structure is as follows:

+ app
    - assets
    - controllers
    - models
    + lib
        - IndicatorWindow.js
    ...

Inside a controller I have the following code:

var uie = require('lib/IndicatorWindow');

But when I run this on an Android phone I get:

Uncaught Error: Requested module not found: lib/IndicatorWindow

I have also tried placing the lib folder outside of app, and using other paths such as /lib/IndicatorWindow and app/lib/IndicatorWindow.

I even tried using Ti.include() instead, with the same result. But I would rather use require() since I prefer using CommonJS modules.

Upvotes: 1

Views: 1740

Answers (2)

Kenneth Nissel
Kenneth Nissel

Reputation: 151

just use var uie = require('IndicatorWindow');

Also make sure it uses exports inside the JS

Upvotes: 2

Wahhab_mirza
Wahhab_mirza

Reputation: 1482

Make a lib folder inside assets folder and paste the js file there and you would be able to require file just like you do in classic :)

Thanks

Upvotes: 2

Related Questions