Cannot resolve dependencies of ClsModule
linardsblk opened this issue · comments
Hi, after implementing ClsModule within my application, I get this dependency error and I am unsure on how to fix. Does anyone have any guidance?
[Nest] 66508 - 07/07/2023, 11:57:53 AM ERROR [ExceptionHandler] Nest can't resolve dependencies of the ClsModule (?, ModuleRef). Please make sure that the argument HttpAdapterHost at index [0] is available in the ClsModule context.
Potential solutions:
- Is ClsModule a valid NestJS module?
- If HttpAdapterHost is a provider, is it part of the current ClsModule?
- If HttpAdapterHost is exported from a separate @Module, is that module imported within ClsModule?
@Module({
imports: [ /* the Module containing HttpAdapterHost */ ]
})
Error: Nest can't resolve dependencies of the ClsModule (?, ModuleRef). Please make sure that the argument HttpAdapterHost at index [0] is available in the ClsModule context.
Potential solutions:
- Is ClsModule a valid NestJS module?
- If HttpAdapterHost is a provider, is it part of the current ClsModule?
- If HttpAdapterHost is exported from a separate @Module, is that module imported within ClsModule?
@Module({
imports: [ /* the Module containing HttpAdapterHost */ ]
})
at Injector.lookupComponentInParentModules (/Users/linards/Documents/projects/fripro/apps/server/node_modules/@nestjs/core/injector/injector.js:248:19)
at Injector.resolveComponentInstance (/Users/linards/Documents/projects/fripro/apps/server/node_modules/@nestjs/core/injector/injector.js:202:33)
at resolveParam (/Users/linards/Documents/projects/fripro/apps/server/node_modules/@nestjs/core/injector/injector.js:123:38)
at async Promise.all (index 0)
at Injector.resolveConstructorParams (/Users/linards/Documents/projects/fripro/apps/server/node_modules/@nestjs/core/injector/injector.js:138:27)
at Injector.loadInstance (/Users/linards/Documents/projects/fripro/apps/server/node_modules/@nestjs/core/injector/injector.js:64:13)
at Injector.loadProvider (/Users/linards/Documents/projects/fripro/apps/server/node_modules/@nestjs/core/injector/injector.js:91:9)
at /Users/linards/Documents/projects/fripro/apps/server/node_modules/@nestjs/core/injector/instance-loader.js:56:13
at async Promise.all (index 0)
at InstanceLoader.createInstancesOfProviders (/Users/linards/Documents/projects/fripro/apps/server/node_modules/@nestjs/core/injector/instance-loader.js:55:9)
I implemented it just like in docs by adding module to AppModule imports
ClsModule.forRoot({
global: true,
middleware: { mount: true },
}),
```
Are you by chance consuming it via a custom npm package?
@linardsblk Hello, could you please provide a little more clarifying information? It is impossible for me to guess what might be wrong from the error message only.
Hey !
I have this problem too, I'm using 3.5.0 version of nestjs-cls and 10.0.5 version of @nestjs/core
@AvnerMaster are you using the nestjs-cls library directly in your app, or through a linked library?
Directly, it is a dependency in my package.json
@AvnerMaster
I just tried with a fresh installation of Nest 10.0.5
and nestjs-cls
3.5.0
and did not notice any issues. Could you provide a repository where this error is reproduced?
My other guess would be that your @nestjs/*
dependencies are not properly matched.
For the record, it is working with these versions:
"@nestjs/common": "^10.0.5",
"@nestjs/core": "^10.0.5",
"@nestjs/platform-express": "^10.0.5",
"nestjs-cls": "^3.5.0",
You are right, I had other libraries that were linked. I managed to fix it by changing the nestjs libraries versions to match my linked libraries nestjs libraries versions. Thank you
I'm glad it's resolved. I'm going to assume that a solution to OP's problem is also similar to yours and close this issue.