运行metamascara时出现的一些错误

The difference between mascara and the extension

Mascara Is in alpha and some of it's behaviors are still undocumented.

1.页面控制台报错

运行eth.accounts出错:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
383.EventEmitter.addListener @ wallet.metamask.io/background.js:56834

好像是要我添加监听吧

解决办法好像是在运行文件时加上 --trace-warnings(打印进程警告的堆栈跟踪(包括废弃警告))命令行选项即可,但是后面发现好像也不行:

http://nodejs.cn/api/cli.html#cli_trace_warnings

node main.js --trace-warnings

并不知道原因,之后查找到了原因,参考:https://segmentfault.com/a/1190000002964630

EventEmitter

在nodejs中有一个EventEmitter类,目的是实现各种事件的event处理。当需要指定绑定事件时,可以使用EventEmitter类的on方法或addListener方法.这两个方法实现原理相同,只是名称不一样.这两个方法都有两个参数,第一个参数为指定事件名 第二个参数为该事件的事件处理函数:

var http = require('http');
var server = http.createServer();
server.addListener('request', function(req, res) {
    console.log('addListener');
    res.end();
})
server.on('request', function(req, res) {
    console.log('on');
    res.end();
})

setMaxListeners()

在默认情况下,同一个指定的事件,最多可以绑定10个事件处理函数。也可以通过下面的方法修改:

var http = require('http');
var server = http.createServer();
server.setMaxListeners(5);
server.addListener('request', function(req, res) {
    console.log('mark');
    res.end();
})
 

也可以指定最多绑定5个,当绑定数超出时,启动nodejs时,会有相应的错误提示。

(node) warning: possible EventEmitter memory leak detected. 6 request listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Server.addListener (events.js:179:15)
    at Object.<anonymous> (/Users/demacia/nodejs-mark/event_emitter.js:41:8)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

然后查到了有一个插件编译并监测到这个warning:https://github.com/niftylettuce/max-listeners-exceeded-warning

可以看看

后面发现好像是浏览器的问题,之前使用的是chrome,后面改成safari后就不再报这样的错了,也不知道为什么,后面查查看??????????

2.错误:

{ Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/user/out/node_modules/babel-preset-stage-0/lib/index.js while parsing file: /Users/user/out/mascara/example/app.js

可能是版本问题:

npm install babel-core@6.24.1 --save-dev
"babel-preset-stage-0": "^6.24.1"
都要版本6
Error: Cannot find module '@babel/core'
 babelify@10 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babelify@8'.

原来 npm install @babel/core和npm install babel-core是一样的,只是版本的不同两者对应的babelify版本也不同

3.问题:

{ [Error: ENOENT: no such file or directory, open '/Users/user/out/node_modules/react-select/dist/react-select.css' while parsing file: /Users/user/out/ui/css.js]


还有react-tooltip-component.css

所以就先将使用到他们的地方先注释掉,(/Users/user/out/ui/css.js)和(/Users/user/out/old-ui/css.js)

4.页面上出错

Cannot GET /favicon.ico

解决方法:参考https://blog.csdn.net/u012217533/article/details/46368251

在页面中加上这么一行代码:

    <span style="white-space:pre">    </span><link href="http://www.lituanmin.com/favicon.ico" rel="icon" type="image/x-icon" />

 5.当我想要调用sendTransaction来看看到底metamascara会不会弹出一个端口,但是下面的data处出了一个错:

web3.eth.sendTransaction({
    from: '0x7DdaD6a67544efB0c51808c77009a7B98Cc81630',
    to: '0x3B896Fb3e31fC9B91921d19B8C7271d1c3af5B35',
    value: '1000000000000000',
    data:'i want to be your friend'//这里出了错
})

出错:Uncaught Error: The data field must be HEX encoded data.

就是data的格式是处理后变成‘0x...’的格式的

所以将data改成web3.utils.sha3('i want to be your friend')

6.然后又出现了下面的这个问题:

Error: Returned error: Unknown address - unable to sign transaction for this address: "0x7ddad6a67544efb0c51808c77009a7b98cc81630"

 是因为我没有打开线上钱包,为这个账户解锁

原文地址:https://www.cnblogs.com/wanghui-garcia/p/9858106.html