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

标签 node.js

大家好,我对 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/

相关文章:

node.js - 如何修复使用 Node 和 nightwatch for 循环时潜在的内存泄漏?

node.js - Firebase 管理员和自定义 token 数据传递到服务器

node.js - Sequelize 不会创建 hasMany 关联,而是创建在 DB 中定义的外键

node.js - Web 浏览器如何对一个简单的 URL 发出多个请求?

javascript - 当请求的凭据模式为 '*' 时,响应中的 Access-Control-Allow-Origin' header 不得为通配符 'include'

javascript - 使用来自客户端 JS 代码的 OAuth 授权代码流 token 是否安全?

javascript - 如何确保通过 socket.io 的消息已收到客户端?

javascript - 继承多对多关联 - 找不到方法

Javascript Nodejs 值未插入数组

javascript - 如何在 https.get 调用 node.js 时禁用证书缓存?