gpt4 book ai didi

node.js - Nodejs 模块未找到错误

转载 作者:太空宇宙 更新时间:2023-11-04 00:50:47 25 4
gpt4 key购买 nike

大家好,我对 Nodejs 很陌生。我尝试使用以下命令来安装 cryptlib 模块:

npm install cryptlib 

安装成功。当我移动到 myproject ->node_modules 时,名为 cryptlib 的文件夹就在那里。

但是当我将其包含在我的 server.js 中时,如下所示

var CryptLib = require('cryptlib'),
_crypt = new CryptLib(),
plainText = 'This is the text to be encrypted',
iv = _crypt.generateRandomIV(16), //16 bytes = 128 bit
key = _crypt.getHashSha256('my secret key', 32), //32 bytes = 256 bits
cypherText = _crypt.encrypt(plainText, key, iv),
originalText = _crypt.decrypt(cypherText, key, iv);

然后它抛出一个错误

module.js:340
throw err;
^
Error: Cannot find module 'cryptlib'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/www/html/testing/server.js:9: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)

那么我该如何修复这个错误呢?任何帮助将不胜感激。

最佳答案

抱歉,在此之前我没有足够的积分来回复评论。

我已将 npm 上的 cryptlib 更新到版本 1.0.3 以解决此问题。现在应该可以了。感谢王庭茂的出色努力。

同时感谢 user3446467 使用该模块。

如果您遇到任何其他问题,请告诉我。

关于node.js - Nodejs 模块未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32565364/

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