Troubleshooting Angular production build errors — Uncaught TypeError: Cannot read properties of undefined (reading ‘a’)

Balram Chavan
2 min readDec 5, 2022

While working with Angular applications, you may find yourself in a position where your development build is successful with ng serve command, application works fine in browser. However, as soon as you create a production build with command ng build -c production you start getting the Uncaught TypeError: Cannot read properties of undefined (reading 'a') where a could be any other property name or object. The console errors will show the compiled JavaScript file with error line number, which are obscured.

So the question is, how to find the actual issue? If you put the exact error in internet search, you will be getting different types of solutions as the error can be from various reason and most of the time different from your project.

One of the solution you can try is to set the sourceMap property to trueof production object (NOT `build`) in angular.json and run ng serve -c production command to keep watching errors while running application in production mode.

Remember to restart ng serve the command every time you change something in angular.json file to take effect.

Now in browser console, you should see the TypeScript file with error line number and with source map enabled, check the source where it fails.

Once you have solved all issues, set sourceMap property to false again, and build and deploy your application.