InversifyJS
InversifyJS copied to clipboard
Inversify inject decorators return null or error
Expected Behavior
lazyInject should be a usable decorator, instead it's just null
or undefined
or something else :-(
Somehow this gets thrown away.
Steps to Reproduce (for bugs)
- Create a container (as in https://github.com/buehler/typescript-hero/blob/develop/src/ioc.ts)
- use
getDecorators
to create the lazy inject decorator - export it with
export { lazyInject };
- get the error below.
Context
Your Environment
- Version used: 4.9.0 with inversify inject decorators 3.1.0
- Environment name and version (e.g. Chrome 39, node.js 5.4): VSCode Extension
- Operating System and version (desktop or mobile): macOS
- Link to your project: https://github.com/buehler/typescript-hero/blob/develop/src/ioc.ts
Stack trace
Here is the error stack: TypeError: ioc_1.lazyInject is not a function
extensionHostProcess.js:292
at Object.<anonymous> (/Users/christoph/Documents/Development/typescript-hero/out/src/declarations/workspace-declarations.js:24:11)
at Object.<anonymous> (/Users/christoph/Documents/Development/typescript-hero/out/src/declarations/workspace-declarations.js:29:3)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Function.J.X.t.getExtensionPathIndex.then.o._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:490:709)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
Hi @buehler, I tried to take a look to your code but I was unable to find lazyInject
. It looks to me like there is some sort of issue with the modules. The error seems to be at:
/src/declarations/workspace-declarations.js:24:11
My guess is that workspace-declarations.js
had a dependency on ioc.js
because it was importing lazyInject` but at runtime the import is not a funcion.
I would try to debug the following to see what is happening. I would expect this issue to be reported by many but so far this is the first case so my guess is that is is likely something wrong with the modules not with inversify-inject-decorators
:
const decorators = getDecorators(container);
const lazyInject = decorators. lazyInject;
Please let me know how it goes and feel free to ask more questions I will b happy to try to help.
@remojansen Hi! I am facing the same problem. I have two modules, let's call them A and B. Module A exports all classes that I want to be injected and module B exports the inversify configuration (container initialization, bindings declaration and decorators creation). I think that the problem comes with circular dependency. Module A is imported in module B to declare the bindings and module A imports the lazyInject decorator from module B, then the error occurs.
I had a similar issue because lazyInject was exported from my configuration after it was used in service. So that's why it was undefined in runtime.
Same issue here. Tried every suggestion here, but still get this error.
Same for me
I am currently facing the same issue.
any resolutions yet, i am also facing this now