我正在尝试实现 NodeJS 的这个 ecc
库,
https://github.com/jpillora/eccjs。
我尝试运行的文件是,
https://github.com/jpillora/eccjs/blob/gh-pages/examples/simple.js
问题是,当我尝试使用 node simple.js
命令运行该文件时,出现以下错误,
eccjs-gh-pages/examples/simple.js:31
var keys = ecc.generate(ecc.ENC_DEC);
^
TypeError: Object function ecc() {
return new ECC();
} has no method 'generate'
at Object.<anonymous> (/home/pi/Project/eccjs-gh-pages/examples/simple.js:31:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
但是,当我使用 html 文件 ( https://github.com/jpillora/eccjs/blob/gh-pages/index.html ) 运行相同的文件时,如下所示,
<script src="examples/simple.js"></script>
我可以在 Chrome 控制台中看到输出。
有人可以告诉我为什么该文件无法使用命令行工作但在通过浏览器执行时工作正常吗?有办法这样做吗?
编辑: 我已经注释掉了以下行,
var ecc = require('../dist/0.1/ecc');
在 example.js 中,然后在命令行中运行它。
最佳答案
因为https://github.com/jpillora/eccjs/blob/gh-pages/dist/0.1/ecc.js
中没有generate
方法,而https://github.com/jpillora/eccjs/blob/gh-pages/dist/0.3/ecc.js
更换,
var ecc = require('../dist/0.1/ecc');
与,
var ecc = require('../dist/0.3/ecc');
应该可以解决您的问题。
关于javascript - 实现eccjs库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39971520/