1

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.

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I wasn't aware that it had to be inside assets ;)
It doesn't. Files from lib directory are accessed without lib/. Anyway moving it to assets will work too.
2

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

Also make sure it uses exports inside the JS

1 Comment

Thank you for your answer, but the problem was that I had to place the lib folder inside the assets folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.