0

I'm using "@angular/cli": "~9.1.13" and when try to build my project in production (ng build --prod) mode, I get an error: ERROR in Cannot read property 'length' of undefined

  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 07 '21 at 12:29
  • There must be more context to the error, this is a standard error that means you tried to determine the length of an object (_probably an array_) but the object was not yet initialised or was null. Post the full error code and the relevant lines of code around that. The line number will show you the variable that is not initialised, but you will have to track the code further back to the point where you expected that object to be initialized to find the real issue. A common fix is to simply check for nulls before trying to process the object. – Chris Schaller Oct 20 '21 at 12:39
  • $ ng build --prod Your global Angular CLI version (10.2.3) is greater than your local version (9.1.13). The local Angular CLI version is used. To disable this warning use "ng config -g cli.warnings.versionMismatch false". ERROR in Cannot read property 'length' of undefined – Mamadou Yaya Diallo Oct 20 '21 at 12:47
  • I had this issue, so I checked `src/environments/environment.ts` and `src/environments/environment.prod.ts` if they existed but they don't, so I created them and i re-run the build it worked for me :) – sohaieb azaiez Nov 30 '22 at 10:25
  • Thank you @sohaiebazaiez for your response . I have both files in my src/environments folder but it didn't work for me – Mamadou Yaya Diallo Dec 02 '22 at 09:43
  • @MamadouYayaDiallo you are welcome ^^ well in this case try to verify the installed versions of Typescript & Webpack if it respects the angular version specification (you can verify with `ng -v`) – sohaieb azaiez Dec 02 '22 at 10:59

0 Answers0