Class-transformer: TypeError: Reflect.getMetadata is not a function

Created on 27 Mar 2017  路  6Comments  路  Source: typestack/class-transformer

The readme says that reflect-metadata should be imported once - "and make sure to import it in a global place, like app.ts". Perhaps I'm missing something here, but if I import it in the root of my React app (I'm using babel to transpile), the transformer complains with the error above. It works only if I move the import 'reflect-metadata' to the actual class that is being serialized. Is that expected behavior?

question

Most helpful comment

Of course there is an entry file - the file where you have ReactDOM.render(<App />, document.(...)).
And if you do import "reflect-metadata" at the top of this file, it will be available at global scope.

All 6 comments

reflect-metadata should be available at the global scope, so importing in entry file should work. If not, configure webpack to bundle this module in global scope.

I'm not sure there is such thing as entry file and/or global scope in React app. The entry file is index.js, but all imports done within file are still scoped to that file and not globally.

Of course there is an entry file - the file where you have ReactDOM.render(<App />, document.(...)).
And if you do import "reflect-metadata" at the top of this file, it will be available at global scope.

Apologies, turns out you're right, after all. My mistake was the order of imports in index.html - obviously, it has to be imported before other things/components using it, so ideally - the closer to the beginning of imports, the better. Once moved there, it worked.

Can be closed.

Hi all!

I am closing this as answered/solved, please feel free to continue the discussion if it's not the case.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings