TypeError: Invalid argument provided in `Service` constructor. Expected class annotated with @Service.
See original GitHub issue
Hello, I’m getting this error:
TypeError: Invalid argument provided in DatabaseService's constructor. Expected class annotated with @Service.
I usually get this error when I have two services that have dependencies on each other, I mean service A is injected into service B and viceversa.
Right now I have this error because I import Logger Service from index.js and not from logger.service.ts
With this I get the error shown above:

Changing the import I don’t get the error:

As I said before, this error happens to me very often when service A has service B as a dependency and vice versa.
By the way, my logger.service.ts:
import {FastifyInstance} from 'fastify';
import {
Service,
getInstanceByToken,
FastifyInstanceToken,
} from 'fastify-decorators';
@Service('LoggerServiceToken')
export class LoggerService {
private readonly fastify =
getInstanceByToken<FastifyInstance>(FastifyInstanceToken);
info(msg: string, ...args: unknown[]) {
this.fastify.log.info(msg, ...args);
}
error(msg: string, ...args: unknown[]) {
this.fastify.log.error(msg, ...args);
}
debug(msg: string, ...args: unknown[]) {
this.fastify.log.debug(msg, ...args);
}
warn(msg: string, ...args: unknown[]) {
this.fastify.log.warn(msg, ...args);
}
trace(msg: string, ...args: unknown[]) {
this.fastify.log.trace(msg, ...args);
}
fatal(msg: string, ...args: unknown[]) {
this.fastify.log.fatal(msg, ...args);
}
}
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
java - Parameter 0 of constructor in ..... Spring Boot
When you create a bean by the constructor approach, all normal classes are usable by and compatible with Spring. That is, the class...
Read more >Entity Annotation & EntityRepository Template causes Psalm ...
Bug Report When updating our doctrine/orm dependency to 2.12.1 we experienced Psalm issues of the following kind in our CI pipeline: ERROR: ...
Read more >Java Method/Constructor in Class Cannot be Applied to Given ...
Whenever a method invocation doesn't match the corresponding method signature, the method X in class Y cannot be applied to given types error...
Read more >Fixing common type problems - Dart programming language
Fixing common type problems · Undefined member · Invalid method override · Missing type arguments · Unexpected collection element type · Constructor initialization ......
Read more >Spring BeanCreationException - Baeldung
or in a Java @Configuration class via the @Bean annotation; or is annotated with @Component, @Repository, @Service, @Controller, and classpath ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @akbarsahata, with
BaseWorkerI think issue can be constructor parameters, dependency injection expects constructable however in your constructor I see configuration, I would suggest trying following approach (without using constructor):cool, I happened to use constructor such way on some places and have it fixed. thanks @L2jLiga 🙏🏻