CKGrafico / inversify-props

Wrapper of Inversify to inject your dependencies in the components, made with TypeScript and compatible with Vue, React and other component libraries.
MIT License
85 stars 9 forks source link

Uncaught Error: @inject called with undefined this could mean that the class undefined has a circular dependency problem #6

Closed bruceauyeung closed 5 years ago

bruceauyeung commented 5 years ago

i am writing a simple electron + vue + typescript app. when debugging in vscode ( which attaches to webpack debugger server), inversify-props works without problem. i can get the result as expected.

无标题1

but when i run electron-vue-ts-element.exe --enable-logging (excutable binary electron-vue-ts-element.exe is generated by yarn electron:build ), that error is printed in stderr.

无标题2

two dependency chains:

HelloWorld.vue -> AnotherWorkerService(non-vue-component) -> WorkerService(non-vue-component)
HelloWorld.vue -> WorkerService(non-vue-component)

inversify-props: "^1.4.3"

bruceauyeung commented 5 years ago

problem solved if manually specifying ids, to be specific:

container.addSingleton<IAnotherWorkerService>(AnotherWorkerService,Types.IAnotherWorkerService); 
@inject(Types.IAnotherWorkerService)  workerService2!:IAnotherWorkerService;

Types.IAnotherWorkerService is the id manually specified. but i don't understand why, maybe my codes are uglified somehow i don't notice yet ? expecting explanations.

bruceauyeung commented 5 years ago

finally i figured out what's the root cause why @inject() doesn't work. it's because my project is created by vue create and vue add electron-builder, and codes are uglified by terser by default. i have already figured out how to enable keep_classnames and keep_fnames. thanks for this wonderful easy-to-use library!

CKGrafico commented 5 years ago

Wow I've just discover all this comments, I think that your issue can help to #5 mmm seems related. How do you think that I can improve my docs to understand better how this works? @bruceauyeung