Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 526
CAlex Avatar asked Dec 15 '18 08:12

CAlex


2 Answers

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.

like image 187
SiddAjmera Avatar answered Sep 18 '22 05:09

SiddAjmera


The import in polyfills.ts is not contained in a default Angular project anymore because Angular only needs it for dev environment.

If you need the polyfill, e.g. for modules like class-transformer, you can add it to the polyfills.ts:

npm i core-js -S

import 'core-js/proposals/reflect-metadata';

like image 40
Mick Avatar answered Sep 18 '22 05:09

Mick