0
votes

I'm working with Atom and Titanium SDK 6.0.1.GA, Alloy 1.9.8 and targeting Android API 22, I created a CommonJS module in the Resources folder but when I try to run my app I get the following error:

In ti:/module.js:303,2

Message: Uncaught Error: Requested module not found: contactClient

Source: throw new Error("Requested module not found: " + request);

V8Exception: Exception occurred at ti:/module.js:303: Uncaught Error: Requested module not found: contactClient

The code inside the module is this:

function getClient(path, successCallback, errorCallback){
  var client = Ti.Network.createHTTPClient({
    onload : successCallback,
    onerror : errorCallback
  });
  client.open('GET', 'http://10.0.12.138:8284/' + path);
  client.send();
}

function getContacts(successCallback, errorCallback){
  getClient('contacts', successCallback, errorCallback);
}

exports.getContacts = getContacts;

The path to my module is Resources/contactClient.js and I try to load it in my index.js like this:

var contactsClient = require('contactClient');

I checked the documentation for CommonJS modules and according to it this shouldn't be a problem.

Am I doing something wrong? I'm placing the js file inside the Resources folder, is it another path?

2

2 Answers

0
votes

The issue was that I was placing the module inside the Resources folder, when appearently the CommonJS modules must be placed inside a lib folder inside the app folder.

So an Alloy projects with CommonJS modules must have the following structure:

root
  -> app
      -> lib
      -> controllers
      -> views
      -> styles
      -> models
0
votes

CommonJs module must be inside folder /app/lib/

you can also use node_module /app/lib/node_modules and it's full compatible since TiSDK 6