microsoft / tsyringe

Lightweight dependency injection container for JavaScript/TypeScript
MIT License
5.18k stars 172 forks source link

@autoInjectable doesn't work with Create React App #188

Open jbrighton-dev opened 2 years ago

jbrighton-dev commented 2 years ago

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",
radnaxel-a commented 2 years ago

@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.