smclab / titaniumifier

Get a Titanium™ SDK CommonJS module out of a Node package!
GNU Lesser General Public License v2.1
95 stars 15 forks source link

Requiring alloy modules #35

Closed AndreaVitale closed 9 years ago

AndreaVitale commented 9 years ago

There's no way to require, inside my module, "alloy/animation"? If I try to build my custom module and, obviously, the build process failed with this message

Error: Cannot find module 'alloy/animation' from /my/module/path
yuchi commented 9 years ago

You can actually work around this issue by saying that it’s a member of nativeDependencies in the package.json. It should let you require files not in scope.

AndreaVitale commented 9 years ago

The build process now complete successfully with this directive in package.json

"nativeDependencies": {
    "alloy/animation": "*" 
}

but.. when I try to use this module inside a test application, this one crash with this error:

[ERROR] :  Script Error Couldn't find module: alloy/animation for architecture: x86_64
yuchi commented 9 years ago

Super strange. That's not a titaniumifier issue anymore. What's that module? Are you sure it's there?

AndreaVitale commented 9 years ago

I've to package a module that use Builtin Titanium Animation and I require it as per the docs! How can I solve? Thank you!

yuchi commented 9 years ago

Looks like it's one of those pieces of the std alloy library that gets loaded only if it is found to be required, and looks like alloy doesn't check modules for such require calls.

Could you try to add require('alloy/animation') somewhere in the app and see if it works?

AndreaVitale commented 9 years ago

In index.js (where I'm trying my titaniumified-module) I tryied:

var animator = require("alloy/animation");

Ti.API.info(animator.HORIZONTAL);

and into console i see "horizontal" as expected.

yuchi commented 9 years ago

And does loading the module works now?

AndreaVitale commented 9 years ago

No, I'll explain in details what I have. Into index.js of the module that I have to tianiumify there is:

module.exports.Animation = require("alloy/animation");

When I titaniumify it and load into the test application the error

[ERROR] :  Script Error Couldn't find module: alloy/animation for architecture: x86_64

occurs.

If I try to normally require the alloy/animation into index.js of application there's no problem.

yuchi commented 9 years ago

Are both a normal, working require and the module on the same app?

What I'm guessing is that if you don't require it in the app (outside modules) the module is not injected in the 'compiled' Resources dir.

AndreaVitale commented 9 years ago

Exactly now it works! Thank you!