tsyringe icon indicating copy to clipboard operation
tsyringe copied to clipboard

@autoInjectable doesn't work with Create React App

Open jbrighton-dev opened this issue 3 years ago • 1 comments

Describe the bug

@autoInjectable doesn't work with Create React App.

To Reproduce

image image image

Expected behavior

I'm sure there's an issue surrounding the way webpack is processing these file, but without ejecting the app, is this possible? We also want to avoid using the container.resolve() syntax. If its possible to get instances of classes from the container in tsx files without either container.resolve() or autoinjectable, then shout.

Version:

"react-scripts": "^5.0.0",
"tsyringe": "^4.6.0",

jbrighton-dev avatar Jan 15 '22 08:01 jbrighton-dev

@JoeBrighton If you are using babel within webpack, make sure to have it configured to work with tsyringe . https://github.com/microsoft/tsyringe#babel

I was facing the same error with @autoInjectable in a blank TS project. Configuring babel fixed the issue for me.

radnaxel-a avatar Jul 20 '22 14:07 radnaxel-a