Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing required @inject or @multiInject annotation in: argument 0 in class t. #1258

Open
reflash opened this issue Oct 27, 2020 · 4 comments
Open

Comments

@reflash
Copy link

@reflash reflash commented Oct 27, 2020

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?

@djflex68
Copy link

@djflex68 djflex68 commented Dec 3, 2020

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 ?

@reflash
Copy link
Author

@reflash reflash commented Dec 3, 2020

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());
@djflex68
Copy link

@djflex68 djflex68 commented Dec 3, 2020

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.

@lkarmelo
Copy link

@lkarmelo lkarmelo commented Dec 31, 2020

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.