Karma cannot find module ‘optimist’

I am trying to install angular phone cat app and run the test cases with karma test runner. I have node v0.10.33 installed. and I have installed karma globally. Now, i am trying to run the test cases with ‘npm test’ and I get following error:

module.js:340
    throw err;
          ^
Error: Cannot find module 'optimist'
    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> (C:meangular-phonecatnode_moduleskarmalibcli.j
s:2: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 Module.require (module.js:364:17)

Any idea ? I thought may be karma is not initialized right and I tried to run ‘karma init’ but same error again.

Update—–

On running ‘npm install’ i get following errors:

npm WARN unmet dependency C:meangular-phonecatnode_moduleskarma requires s
[email protected]'~0.9.13' but will load
npm WARN unmet dependency C:meangular-phonecatnode_modulessocket.io,
npm WARN unmet dependency which is version 1.2.0
npm WARN unmet dependency C:meangular-phonecatnode_moduleskarma requires g
[email protected]'~3.2.7' but will load
npm WARN unmet dependency C:meangular-phonecatnode_modulesglob,
npm WARN unmet dependency which is version 4.1.4
npm WARN unmet dependency C:meangular-phonecatnode_moduleskarma requires m
[email protected]'~0.2' but will load
npm WARN unmet dependency C:meangular-phonecatnode_modulesminimatch,
npm WARN unmet dependency which is version 1.0.0
npm WARN unmet dependency C:meangular-phonecatnode_moduleskarma requires u
[email protected]'~2.0.4' but will load
npm WARN unmet dependency C:meangular-phonecatnode_modulesuseragent,
npm WARN unmet dependency which is version 2.1.2
npm WARN unmet dependency C:meangular-phonecatnode_moduleskarma requires c
[email protected]'~2.12.0' but will load
npm WARN unmet dependency C:meangular-phonecatnode_modulesconnect,
npm WARN unmet dependency which is version 3.3.3
npm WARN unmet dependency C:meangular-phonecatnode_modulesbowernode_modul
eshandlebars requires [email protected]'~0.3' but will load
npm WARN unmet dependency C:meangular-phonecatnode_modulesoptimist,
npm WARN unmet dependency which is version 0.6.1
npm WARN unmet dependency C:meangular-phonecatnode_modulesbowernode_modul
esbower-registry-clientnode_modulesrequestnode_modulesform-data requires as
[email protected]'~0.9.0' but will load
npm WARN unmet dependency C:meangular-phonecatnode_modulesbowernode_modul
esbower-registry-clientnode_modulesasync,
npm WARN unmet dependency which is version 0.2.10
npm WARN unmet dependency C:meangular-phonecatnode_modulesbowernode_modul
esinsightnode_modulesinquirernode_modulescli-colornode_modulesd requires
[email protected]'~0.10.2' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
npm WARN unmet dependency C:meangular-phonecatnode_modulesbowernode_modul
esinsightnode_modulesinquirernode_modulescli-colornode_modulestimers-ext
requires [email protected]'~0.10.2' but will load

Answer

Try do next steps before run npm install

  • remove folder node_modules from your project
  • run npm cache clean
  • run npm install