InversifyJS
InversifyJS copied to clipboard
Missing required @inject or @multiInject annotation in: argument 0 in class t.
I have an issue resolving 3rd party class and the message I get is a bit cryptic.
So I decorate PrismaClient with injectable and bind to the container
decorate(injectable(), PrismaClient);
container.bind<PrismaClient>(TYPES.PrismaClient).to(PrismaClient);
In my ctor I inject it like that:
constructor(
@inject(TYPES.PrismaClient) private readonly client: PrismaClient
) {}
Expected Behavior
PrismaClient is resolved properly
Current Behavior
"Error: Missing required @inject or @multiInject annotation in: argument 0 in class t.",
" at getConstructorArgsAsTarget (/<root>/node_modules/inversify/lib/planning/reflection_utils.js:49:19)",
" at getConstructorArgsAsTargets (/<root>/node_modules/inversify/lib/planning/reflection_utils.js:61:22)",
" at getTargets (/<root>/node_modules/inversify/lib/planning/reflection_utils.js:27:30)",
" at Object.getDependencies (/<root>/node_modules/inversify/lib/planning/reflection_utils.js:12:19)",
" at /<root>/node_modules/inversify/lib/planning/planner.js:106:51",
" at Array.forEach (<anonymous>)",
" at _createSubRequests (/<root>/node_modules/inversify/lib/planning/planner.js:94:20)",
" at /<root>/node_modules/inversify/lib/planning/planner.js:115:17",
" at Array.forEach (<anonymous>)",
" at /<root>/node_modules/inversify/lib/planning/planner.js:114:26"
Could you help me with some hints maybe? What am I doing wrong?
I have the same issue after the code has been minified by Angular (using internally TerserPlugin). All constructors are renamed to minified letters. I don't know how to avoid this problem, did you find a solution/workaround ?
I have the same issue after the code has been minified by Angular (using internally TerserPlugin). All constructors are renamed to minified letters. I don't know how to avoid this problem, did you find a solution/workaround ?
I'm using this as a workaround in my project:
container
.bind<PrismaClient>(TYPES.PrismaClient)
.toDynamicValue(() => new PrismaClient());
Thanks for your workaround. Unfortunately, the problem ist slightly different in my case, since the dependency I'm trying to bind on isn't an external library, but an injectable class that belongs to my project (which itself has other dependencies). Therefore I cannot use new MyClass() as you do, because constructor and properties won't be injected automatically anymore. I'm wondering that noone has been encountering the same problem so far. This should be relatively common, since it happens as soon as the code is minified.
@djflex68 ~~I've encountered this problem and figuring out what was wrong has driven me insane, because google searches made it seem like no one had the same problem.~~
EDIT: after research, it seems my issue was not related to inversify.js
Hi @reflash, your code should work, could you help me to reproduce your issue? Do you have a minimal example?
I've been trying the case you describe in my local environment and it works.