-
Notifications
You must be signed in to change notification settings - Fork 28
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
Error using nestjs-cls in an external module #51
Comments
First thing that comes to mind, which is pretty common, is that the versions of If you want me to investigate further, I'll need some reproducible example that I could look at. |
I create two repositories to reproduce. A lib using nestjs-cls: https://github.com/alessandrosangalli/lib-with-cls You can clone both in the same folder like /src/lib-with-cls and /src/app-using-lib because the app is pointing to local lib in package json "lib-with-cls": "file:../lib-with-cls". To reproduce: You should see 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. Both repositories are created from the same NestJS version (9.1.4). This just happens when nestjs-cls is in a lib, when i use directly in my app works fine. |
Yep, the issue is definitely with duplicate package install. Setting the dependencies to This is a known problem of NPM (you can read more about it here npm/npm#7742, maybe it will give you some ideas about how to solve it). The general advice is to avoid using the |
In real app my lib is published, so peer dependencies solved the problem. Thank you! |
I have a external module (in a private repository) using nestjs-cls
MyModuleUsingNestjsCls
imports
ClsModule.forRoot({
global: true,
middleware: { mount: true },
})
provide: MyServiceUsingClsService
exports: MyServiceUsingClsService
This module has a provider that uses ClsService:
class MyService constructor(private readonly clsService: ClsService) {}
This app works fine when i start this module, the cls service also works.
If i import MyModuleUsingNestjsCls in another nestjs app like this:
MyAnotherAppModule imports MyModuleUsingNestjsCls (from an repository like import { MyModuleUsingNestjsCls } 'my-private-lib')
I have the following 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.
Any idea why this happens?
The text was updated successfully, but these errors were encountered: