2013-10-10 13 views
7

tôi có một mã kiểm tra và cố gắng để chạy nóKhông thể tìm thấy mô-đun './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); 
    }) 
    }) 
}) 

khi tôi chạy nó tôi đang nhận được lỗi

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 

tôi bao gồm mocha và nên trong package.json nhưng tại sao tôi phải đối mặt với lỗi này .should là hiển thị trong các mô-đun nút của tôi cũng.please hướng dẫn

Trả lời

7

Tôi gặp phải vấn đề tương tự và tôi nghĩ đó là vì gói should đã được cập nhật hai giờ trước (và nó có thể đã phá vỡ một cái gì đó).

npm install [email protected] 

thực hiện thủ thuật.

EDIT

Phiên bản 2.0.1 đã khắc phục sự cố.

+0

cảm ơn rất nhiều câu trả lời đúng: D – Nitin

+0

có lỗi nào trong 1.3.0 không? Tôi đang gặp vấn đề http://stackoverflow.com/questions/19303240/object-object-has-no-method-type – Nitin

+0

@Nitin Tôi không biết, nhưng phiên bản 2.0.1 là trực tuyến, vì vậy bạn chắc chắn nên dùng thử! –

2

Đơn giản chỉ có nghĩa là should từ NPM chưa được cài đặt. Chỉ cần sử dụng

sudo npm install should 

Điều này có nghĩa là phải cài đặt should từ quản lý gói nút.

Hy vọng nó sẽ làm cho nội dung rõ ràng hơn.

Chúc mừng.

+0

Xin chào, đây không phải là ý tưởng hay vì nó không thể di chuyển sang các cài đặt khác của mã dự án của bạn. Nếu tôi git kiểm tra dự án và thử chạy thử nghiệm, các bài kiểm tra sẽ không yêu cầu tôi phải cài đặt npm -g. –

Các vấn đề liên quan