InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

Inversify inject decorators return null or error

Open buehler opened this issue 7 years ago • 8 comments

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)

  1. Create a container (as in https://github.com/buehler/typescript-hero/blob/develop/src/ioc.ts)
  2. use getDecorators to create the lazy inject decorator
  3. export it with export { lazyInject };
  4. 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)

buehler avatar Jan 25 '18 07:01 buehler

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 avatar Feb 02 '18 01:02 remojansen

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

juanenrisley avatar Jul 18 '18 14:07 juanenrisley

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.

Halynsky avatar Aug 30 '18 02:08 Halynsky

Same issue here. Tried every suggestion here, but still get this error.

timargra avatar Sep 25 '18 15:09 timargra

Same for me

Melzar avatar Feb 02 '20 00:02 Melzar

I am currently facing the same issue.

Theshedman avatar Dec 19 '21 21:12 Theshedman

any resolutions yet, i am also facing this now

lakeman-sage avatar Nov 30 '22 13:11 lakeman-sage