node.js - 找不到模块 './lib/should'

标签 node.js npm mocha.js should.js

我有一个测试代码并尝试运行它

var should = require("should")
describe('Array', function(){
  describe('#indexOf()', function(){
    it('should return -1 when the value is not present',function(){
      [1,2,3].indexOf(5).should.equal(-1);
      [1,2,3].indexOf(0).should.equal(-1);
    })
  })
})

当我运行它时出现错误

Error: Cannot find module './lib/should'
    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> (/home/ritesh/projects/passport-topcoder/node_modules/should/index.js:2:18)
    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 Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/ritesh/projects/passport-topcoder/test/module.test.js:1:76)
    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 Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /usr/local/lib/node_modules/mocha/lib/mocha.js:152:27
    at Array.forEach (native)
    at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:149:14)
    at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:306:31)
    at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:348:7)
    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:901:3

我在 package.json 中包含了 mocha 和 should 但为什么我会遇到这个错误。should 也在我的 Node 模块中显示。请指导

最佳答案

我遇到了同样的问题,我认为这是因为 should 包已经在两个小时前更新了(它可能已经损坏了某些东西)。

npm install should@1.3.0

成功了。

编辑

2.0.1 版修复了这个问题。

关于node.js - 找不到模块 './lib/should',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19301763/

相关文章:

javascript - 个性化列表列 - Nodejs(NPM)

javascript - 适用于移动应用程序的 Node.js Web 服务

node.js - 如何自动化API获取数据请求?使用网络套接字时

javascript - 用于客户端-服务器通信和安全的 api-key

javascript - 通过nodejs从mongodb获取数据并express到html页面

node.js - Mocha 单元测试: where to create variables

javascript - 如何构建用于部署的静态文件

android - Cordova 错误ENOENT

node.js - 抑制 chai 中的日志输出

node.js - 使用 mocha 测试异步/等待时使用 done() 的正确方法