gpt4 book ai didi

javascript - 实现eccjs库时出错

转载 作者:行者123 更新时间:2023-11-28 05:27:59 25 4
gpt4 key购买 nike

我正在尝试实现 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com