Search code examples
angularmetadatatypeerrorproduction

Uncaught TypeError: Reflect.defineMetadata is not a function on Angular 7 Production Build


I am trying to deploy a production build of my Angular 7 app to Azure. I was able to easily deploy it when running ng build but when I attempted the full ng build --prod I receive this error below in console and the page does not load. This also happens when running the app on a localhost server as well.

Uncaught TypeError: Reflect.defineMetadata is not a function

enter image description here

I have searched, but I cannot find a reference to this exact error. I see most of the results are for this: Uncaught TypeError: Reflect.getMetadata is not a function


Solution

  • Make sure that you have reflect-metadata installed. Also try adding this line to your polyfills.ts file:

    import 'reflect-metadata'
    

    OR

    import 'core-js/es7/reflect';
    

    Ideally, this(the second import statement) is already a part of the polyfills.ts file.

    That should make it work.