angularcomponentscommand-line-interfaceangular7generate

Angular 7 CLI ng generate component error: 'Cannot read property 'sourceRoot' of undefined'


I was receiving the following error when I tried to run the following command on the CLI:

ng generate component [component-name]

I kept getting:

Cannot read property 'sourceRoot' of undefined

I am guessing I started getting it after updating the version of angular I was on. Cannot read property 'sourceRoot' of undefined

See reply for solution.


Solution

  • To fix the issue I had to go to my Angular.json folder.

    1. Search "e2e"
    2. Update the 'root' from 'e2e/' to '/'. The location is under '[project-name]-e2e'

    enter image description here

    Once updated I was able to run the command

    ng generate component [component-name]
    

    No issues came up

    ng generate component product-search