问题描述
我想将web3安装到我的移动应用程序项目中.
但是,我在访问它的情况下遇到了问题,而没有一堆红色的屏幕说我无法访问其中的这些文件.我试图手动更新路径等;
我所做的是在我的应用程序夹中:npm install web3
然后,我在我的应用程序目录中看到node_modules文件夹...但是,我无法使用简单的index.js文件中的模块:
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();
现在,我将文件夹从node_modules粘贴到了我在App文件夹下创建的lib中,并尝试访问其中的dist以访问web3.min,然后尝试了很多其他事情,没有运气...其他人是否有这样的问题或有解决方案?
推荐答案
此模块无法正常工作. 较小的差异:
SDK没有节点核心模块的替代品
我认为这实际上是一个主要区别,因为许多节点模块或其依赖项都使用node.js核心模块.例如,web3使用一个称为XMLHttpRequest的模块,该模块又使用node.js core url 模块.钛会出现一个错误,说"找不到模块:架构的URL:x86_64'.很可能还有其他几个核心模块依赖性.
至少目前,Node.js支持似乎最适合独立JS库.想想momentjs或underscore(尽管它们已经内置在合金中).
问题描述
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?
推荐答案
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).