Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
115
rated 0 times [  119] [ 4]  / answers: 1 / hits: 40934  / 8 Years ago, mon, april 25, 2016, 12:00:00

I am trying to follow a first example from https://mochajs.org/



Done this



$ npm install -g mocha


Got



C:Windowssystem32>npm install -g mocha
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install th
e latest version of pug instead of jade
npm WARN deprecated [email protected]: graceful-fs version 3 and before will fai
l on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possibl
e.
C:UsersTestUserAppDataRoamingnpm_mocha -> C:UsersTestUserAppDataRoamin
gnpmnode_modulesmochabin_mocha
C:UsersTestUserAppDataRoamingnpmmocha -> C:UsersTestUserAppDataRoaming
npmnode_modulesmochabinmocha
[email protected] C:UsersTestUserAppDataRoamingnpmnode_modulesmocha
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected])


Also installed chai (sorry, I originally forgot to mention it)



C:Windowssystem32>npm install -g chai
[email protected] C:UsersTestUserAppDataRoamingnpmnode_moduleschai
├── [email protected]
├── [email protected]
└── [email protected] ([email protected])


And here is the code



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


Keep getting



Error: Cannot find module 'chai'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (c:gitdevelopSendTexttesttest2.js:1:76)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)


What am I doing wrong?


More From » node.js

 Answers
10

You have installed chai globally (with -g option), that's why require don't find it.



You need to install it locally (on your node_modules directory), so that require can find it.



To do so, type:



npm install --save-dev chai

[#62411] Friday, April 22, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandra

Total Points: 708
Total Questions: 100
Total Answers: 84

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
sandra questions
Tue, Jun 30, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Fri, May 31, 19, 00:00, 5 Years ago
;