2013-10-10 31 views
7

我有一個測試代碼,並試圖運行它找不到模塊「./lib/should」

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,但爲什麼我面臨這個錯誤。應該顯示在我的節點模塊also.please指導

回答

7

我面臨同樣的問題,我認爲這是因爲should包已更新兩個小時前(和它可能有破碎的東西)。

npm install [email protected] 

訣竅。

編輯

修正了版本2.0.1的問題。

+0

非常感謝您的正確答案:D – Nitin

+0

在1.3.0中是否還有任何錯誤??我面臨的問題http://stackoverflow.com/questions/19303240/object-object-has-no-method-type – Nitin

+0

@Nitin我不知道,但2.0.1版是在網上,所以你一定要試試看! –

2

它只是意味着從NPM should尚未安裝。只需使用

sudo npm install should 

這意味着它應該從節點包安裝should管理。

希望它使東西更清晰。

乾杯。

+0

咦,這不是一個好主意,因爲它無法移植到你的項目代碼的其他安裝。如果我的git簽出的項目,並嘗試運行測試,測試不應該要求我NPM安裝-g。 –