You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CRA2 doesn't work with reflect-metadata package #6388
Just follow the steps from the Reproducible Demo part and open console in browser.
Expected Behavior
Browsers console should print someProperty type: Number.
Actual Behavior
It prints couldn't get the type :(.
Reproducible Demo
git clone git@github.com:elderapo/cra2-reflect-metadata-bug.git
cd cra2-reflect-metadata-bug
yarn
yarn start
The problem
I think the problem is that babel completely strips out TS types before compilation process which makes it impossible for reflect-metadata package to do its work.
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.
I understand that there might not be an easy fix becuase of how babel compiles typescript. However, there are few nice libraries (ex. InversifyJS) that heavily rely on reflect-metadata package and the fact that cra-2 is not complatible is really discouraging.
Reacted by Sebastian Obentheuer, David Totrashvili, Chrys Exaucet, Olivier Giniaux and Vitaly Kondratiev
Any likelihood of getting babel-plugin-transform-typescript-metadata added? It seems like a sensible default if Typescript is used anywhere, since a lot of libraries use the type metadata.
Reacted by elderapo, Val Akhmedov and Tim Phillips
Can anyone confirm the stability of the metadata proposal? What stage is it in? Last time I checked I seem to remember it not having been proposed yet as they were waiting for decorators to be later stage?
We typically don't support early stage proposals in CRA as they are too volatile. For example the decorators proposal changed drastically during the first couple stages.
Now with CRA 4.0 craco breaks, and I don't know if they gonna fix that, after all craco is a big hack, and not a real fix for the main issue that we can't configure babel, or extract metadata, and exporting metadata is a must now days. We have a dependency library that we use in our projects with a useDependency hook, and we need this feature. We can't upgrade to CRA 4.0 because that breaks craco, but the old CRA is old, and throws random linter errors when working with complex generic cases. Is there any possibility at all to fix this inside CRA without the need of a hack?
Does anyone know how to handle the issue with transpilation of es6 syntax with babel? When I try to use tsyringe with craco, I run into the problem when using autoinjection
"TypeError: Class constructor x cannot be invoked without 'new'"
Does anyone know how to handle the issue with transpilation of es6 syntax with babel? When I try to use tsyringe with craco, I run into the problem when using autoinjection "TypeError: Class constructor x cannot be invoked without 'new'"
edit tsconfig.json, change "target" value from "es5" to "es6" or more
Activity
stale commentedon Mar 12, 2019
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.
elderapo commentedon Mar 13, 2019
Are there any plans regarding this issue?
I understand that there might not be an easy fix becuase of how babel compiles typescript. However, there are few nice libraries (ex.
InversifyJS) that heavily rely onreflect-metadatapackage and the fact thatcra-2is not complatible is really discouraging.iansu commentedon Mar 14, 2019
I think this would need to be addressed in Babel. Can you find or create an issue there and link to it here?
elderapo commentedon Mar 14, 2019
@iansu, here you go babel/babel#9681.
magneticflux- commentedon Apr 13, 2019
Any likelihood of getting babel-plugin-transform-typescript-metadata added? It seems like a sensible default if Typescript is used anywhere, since a lot of libraries use the type metadata.
iansu commentedon Apr 14, 2019
That might be possible. It depends how mature that plugin is and what kind of impact it has on build performance. cc @ianschmitz @mrmckeb
ianschmitz commentedon Apr 27, 2019
Can anyone confirm the stability of the metadata proposal? What stage is it in? Last time I checked I seem to remember it not having been proposed yet as they were waiting for decorators to be later stage?
We typically don't support early stage proposals in CRA as they are too volatile. For example the decorators proposal changed drastically during the first couple stages.
xiaoxiangmoe commentedon Apr 28, 2019
@iainbeeston can we config babel and eslint in CRA?In this way, the responsibility for maintaining the plugin of babel can be given to the user.
Obiwarn commentedon Jun 26, 2020
Is there any workaround for this to get any dependency injection library to run?
rmoedt commentedon Jun 26, 2020
@Obiwarn You can use a package like https://github.com/arackaf/customize-cra, which allows you to load extra babel plugins without ejectting cra. You can then include the babel-plugin-transform-typescript-metadata plugin
Obiwarn commentedon Jun 26, 2020
@rmoedt I installed both and tried
But tsyringe still throws
Error: TypeInfo not knownkmannislands commentedon Jul 1, 2020
@Obiwarn I was running into the same issue with CRA x TSyringe. I didn't try
customize-crabutcracodid it for me. See microsoft/tsyringe#29 (comment)Obiwarn commentedon Jul 3, 2020
@kmannislands Thank you. I tried it but now, in the classes I use mobx-decorators I get:
TypeError: Reflect.metadata is not a functionelderapo commentedon Jul 3, 2020
@Obiwarn You need to install and import
reflect-metadatapackage.Obiwarn commentedon Jul 3, 2020
@elderapo argh....forgot the import. Thank you!
Now it works!
pabloordonez commentedon Oct 29, 2020
Now with CRA 4.0 craco breaks, and I don't know if they gonna fix that, after all craco is a big hack, and not a real fix for the main issue that we can't configure babel, or extract metadata, and exporting metadata is a must now days. We have a dependency library that we use in our projects with a
useDependencyhook, and we need this feature. We can't upgrade to CRA 4.0 because that breaks craco, but the old CRA is old, and throws random linter errors when working with complex generic cases. Is there any possibility at all to fix this inside CRA without the need of a hack?ogxd commentedon Jul 4, 2021
I installed craco today and used the configuration from @kmannislands and it worked ❤️
JMLX42 commentedon Nov 1, 2021
It worked but I had to add
import 'reflect-metadata'in the very file where I'm using the@Typedecorator.Is there anyway to import it just once in
intex.tsxand be done with it?jbrighton-dev commentedon Dec 22, 2021
Does anyone know how to handle the issue with transpilation of es6 syntax with babel? When I try to use tsyringe with craco, I run into the problem when using autoinjection
"TypeError: Class constructor x cannot be invoked without 'new'"
thongxuan commentedon Mar 22, 2022
edit tsconfig.json, change "target" value from "es5" to "es6" or more