问题
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