npm install web3 into Appcelerator Titanium SDK > 6.x

孤街醉人 提交于 2019-12-24 07:46:50

问题


I would like to install web3 into my mobile App project.

However I am having issues with accessing it without having a buch of red screens saying I can't access these files within it. I tried to manually update the paths etc;

What I've done is in my App folder: npm install web3

Then I see the node_modules folder in my App directory... however, I am not able to require the module in my index.js file with a simple:

var Web3 = require('web3'); // throws error
var web3 = new Web3();

function doClick(e) {
    var version = web3.version.api;
    $.label.text = "Web3 version: " + version;
}

$.index.open();

Now I've pasted the folder from the node_modules into a lib I created under App folder, and tried to access the dist within that to access web3.min, then tried a whole lot of other things, with no luck... has anybody else had such issue or have a solution?


回答1:


This module isn't going to work. From the Appc Node.js Support doc under minor differences:

SDK doesn't have replacements for Node's core modules

I think this actually a major difference, as many node modules or their dependencies use Node.js core modules. For example, web3 uses a module called XMLHttpRequest, which in turn uses the Node.js core url module. Titanium will throw an error saying it 'couldn't find module: url for architecture: x86_64'. There are most likely several other core module dependencies.

The Node.js support, at least currently, appears to be best suited for standalone js libraries. Think momentjs or underscore (though those are already built-in to Alloy).



来源:https://stackoverflow.com/questions/45041398/npm-install-web3-into-appcelerator-titanium-sdk-6-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!