reflect-metadata icon indicating copy to clipboard operation
reflect-metadata copied to clipboard

Reflect.getMetadata is not a function

Open kesemdavid opened this issue 8 years ago • 6 comments

So i have update to the latest RC7 of angular2 and now im getting this error :

Reflect.getMetadata is not a function

What can I do to fix this issue, I'm using the 0.1.2 version. (Also tried with the latest 0.1.8)

Thanks in advance!

kesemdavid avatar Sep 16 '16 21:09 kesemdavid

I had a similar problem upgrading to angular2 2.0.1 from 2.0.0-rc5. At the same time I upgraded angular-cli from 1.0.0-beta.11-webpack.2 to 1.0.0-beta.15.

when running 'ng init' i was a bit prescriptive in what I allowed angular-cli to update: one of the things it wanted to change was main.ts, adding the line import './polyfills.ts'; to the top of main.ts fixed it for me.

blowback avatar Sep 25 '16 17:09 blowback

I'm also getting this error. On the latest version of Angular and not using angular-cli. In my package.json I have: "reflect-metadata": "^0.1.8",

I thought polyfills were no longer used?

Davy-F avatar Oct 28 '16 12:10 Davy-F

Any update on this? I too am having this problem.

BergerLand avatar Dec 15 '16 23:12 BergerLand

I wanted to use reflect-metadata without Angular just to include it in a project with run-time type introspection of class properties, so I tried a very simple example with tsconfig.json target=ES2017, module=2015 and a simple test.ts:

import 'reflect-metadata';
function logType(target : any, key : string) {
   var t = Reflect.getMetadata("design:type", target, key);
   console.log(`${key} type: ${t.name}`);
}
export class Demo {
  @logType
  test: Date;
}
console.log(Reflect.getMetadata('design:type', new Demo(), "test"));

And it complains: error TS2339: Property 'getMetadata' does not exist on type 'typeof Reflect'. The reason is that TypeScript thinks that Reflect means the lib.es2015.reflect.d.ts (because ES2015 also defines Reflect symbol on global namespace). How do I solve this?

httpdigest avatar Feb 09 '18 11:02 httpdigest

I added the reflect-metadata types and that resolved my problem yarn add --dev @types/reflect-metadata

bashleigh avatar Jul 05 '18 10:07 bashleigh

I ran into this problem inside a lib. I resolved it by following @bashleigh's example and installing the types,

npm i --save @types/reflect-metadata

But also had to add an entry within tsconfig.lib.json:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    ...
    "types": [
      "reflect-metadata"
    ]
  }
}

schtauffen avatar Apr 25 '19 18:04 schtauffen