Search code examples
javascriptangularjsnpmyeomanyeoman-generator

Error: Cannot find module 'ansi-styles' in AngularJS with Yeoman generator


My code was working previously before, but seems to have stopped working. I tried yo angular:route api but this error was returned:

Error: Cannot find module 'ansi-styles'
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> (/usr/local/lib/node_modules/generator-angular/node_modules/chalk/index.js:2:12)
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)

I have added all the dependencies required to my package file, update npm (which is now on 2.0.0alpha), all npm packages, and ran npm install. The site still works when I grunt serve.


Solution

  • (The O.P.):

    I found the reason I got the error. I had to change the npm root folder and reinstalled my packages in the default folder and now it works.