Nest can't resolve dependencies of the MikroOrmCoreModule (Symbol(mikro-orm-module-options), ?). Please make sure that the argument ModuleRef at index [1] is available in the MikroOrmCoreModule context.
See original GitHub issueDescribe the bug
I’ve tried several configurations, but I keep getting this error.
Stack trace
[Nest] 69475 - 07/17/2021, 4:01:41 PM LOG [NestFactory] Starting Nest application...
[Nest] 69475 - 07/17/2021, 4:01:41 PM LOG [InstanceLoader] ConfigModule dependencies initialized +188ms
[Nest] 69475 - 07/17/2021, 4:01:41 PM LOG [InstanceLoader] DomainModule dependencies initialized +1ms
[Nest] 69475 - 07/17/2021, 4:01:41 PM LOG [InstanceLoader] MikroOrmModule dependencies initialized +0ms
[Nest] 69475 - 07/17/2021, 4:01:41 PM ERROR [ExceptionHandler] Nest can't resolve dependencies of the MikroOrmCoreModule (Symbol(mikro-orm-module-options), ?). Please make sure that the argument ModuleRef at index [1] is available in the MikroOrmCoreModule context.
Potential solutions:
- If ModuleRef is a provider, is it part of the current MikroOrmCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within MikroOrmCoreModule?
@Module({
imports: [ /* the Module containing ModuleRef */ ]
})
Error: Nest can't resolve dependencies of the MikroOrmCoreModule (Symbol(mikro-orm-module-options), ?). Please make sure that the argument ModuleRef at index [1] is available in the MikroOrmCoreModule context.
Potential solutions:
- If ModuleRef is a provider, is it part of the current MikroOrmCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within MikroOrmCoreModule?
@Module({
imports: [ /* the Module containing ModuleRef */ ]
})
at Injector.lookupComponentInParentModules (/App/node_modules/@my-org/api/node_modules/@nestjs/core/injector/injector.js:189:19)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at Injector.resolveComponentInstance (/App/node_modules/@my-org/api/node_modules/@nestjs/core/injector/injector.js:145:33)
at resolveParam (/App/node_modules/@my-org/api/node_modules/@nestjs/core/injector/injector.js:99:38)
at async Promise.all (index 1)
at Injector.resolveConstructorParams (/App/node_modules/@my-org/api/node_modules/@nestjs/core/injector/injector.js:114:27)
at Injector.loadInstance (/App/node_modules/@my-org/api/node_modules/@nestjs/core/injector/injector.js:47:9)
at Injector.loadProvider (/App/node_modules/@my-org/api/node_modules/@nestjs/core/injector/injector.js:69:9)
at async Promise.all (index 0)
at InstanceLoader.createInstancesOfProviders (/App/node_modules/@my-org/api/node_modules/@nestjs/core/injector/instance-loader.js:44:9)
To Reproduce
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ConfigModule, DatabaseModule } from '@my-org/infra';
import { ApiModule, ApiController, ApiService } from '@my-org/api';
import { Config } from '@my-org/config';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { getRootPath } from '@my-org/utils';
import { DomainModule } from '@project/domain';
import { ProjectAppController } from './app.controller';
import { ProjectAppService } from './app.service';
@Module({
imports: [
ConfigModule,
DomainModule,
GraphQLModule.forRoot({
debug: false,
playground: true,
autoSchemaFile: getRootPath('apps/project-api/graphql-schema.gql'),
path: Config.serviceGraphqlApiEndpoint,
}),
MikroOrmModule.forRoot(
Config.getMikroOrmConfig({
migrations: {
migrationsList: [],
},
})
),
DatabaseModule,
],
controllers: [ProjectAppController, ApiController],
providers: [ProjectAppService, ApiService],
})
export class AppModule extends ApiModule {}
DomainModule imports ResourceModule
import { Module } from '@nestjs/common';
import { ResourceService } from './resource-manifest.service';
import { ResourceResolver } from './resource-manifest.resolver';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Resource } from './entities/resource-manifest.entity';
@Module({
providers: [ResourceResolver, ResourceService],
imports: [MikroOrmModule.forFeature([Resource])],
})
export class ResourceModule {}
Expected behavior
To see dependencies resolved
Additional context Add any other context about the problem here.
Versions
Dependency | Version |
---|---|
node | v12.18.3 |
typescript | 4.3.5 |
"@mikro-orm/core": "^4.5.7",
"@mikro-orm/migrations": "^4.5.7",
"@mikro-orm/nestjs": "^4.2.0",
"@mikro-orm/postgresql": "^4.5.7",
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Nest can't resolve dependencies of the ItemsService ...
Nest can't resolve dependencies of the ItemsService (?). Please make sure that the argument at index [0] is available in the AppModule context....
Read more >Common errors - FAQ - A progressive Node.js framework
Nest can't resolve dependencies of the <provider> (?). Please make sure that the argument ModuleRef at index [<index>] is available in the ...
Read more >Using MikroORM with NestJS framework
Easiest way to integrate MikroORM to Nest is via @mikro-orm/nestjs module. ... file mikro-orm.config.ts and then call the forRoot() without any arguments.
Read more >The nestjs from mikro-orm - Coder Social
Nest can't resolve dependencies of the MikroOrmCoreModule (Symbol(mikro-orm-module-options), ?). Please make sure that the argument ModuleRef at index [1] ...
Read more >Nest can't resolve dependencies of the UserService (?, +) ...
Nest can't resolve dependencies of the UserService (?, +). Please make sure that the argument at index [0] is available in the current...
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
Preface
I encountered this error and was stuck for a while, but recently figured it out and wanted to post my issue+solution in case someone else stumbles on it.
The issue
The core issue was that I had multiple installations of nestjs, although they had the same version, but just in different folders. And then the mikro-orm packages were accessing a different installation of NestJS than my application. I think this led to the error that ModuleRef couldn’t be found, because the ModuleRef that the mikro-orm modules wanted to use is from a different NestJS installation than the one that my application was actually providing.
The reason it was so hard to figure out is that I am using yarn v1 workspaces and my application is just a single package within the workspace. And my package within the workspace had (for some unknown reason) its own installation of NestJS, whereas mikro-orm was properly hoisted (hoisting means the module is installed in the root of the workspace instead of just the individual package) and installed in the root of my workspace, in addition to the aforementioned separate installation of NestJS that was also hoisted and installed in the root of my workspace.
So the structure looked like this:
And the confusing part was that the yarn.lock indicated that only a single version of the @nestjs/… packages were installed. Only after manually checking the directories I figured this out.
How I solved it
I could finally solve it by setting the
nohoist
attribute in the package.json within my-subpackage, to force yarn to not hoist the nestjs and mikro-orm packages.So the package.json inside of my-subpackage finally looked like this:
Afterwards, it was important to remove the node_modules directories and remove the existing yarn.lock file, so that yarn actually applies the nohoist rules.
Additionally, in case you encounter this error but aren’t using yarn workspaces, my advice is just to go through the node_modules folders and figure out if there are any multiple versions of @nestjs/… or @mikro-orm/… packages installed, and if so, you’ll have to figure out why and how to force NPM/Yarn (or whichever package manager of your choice) to only install a single version of these packages.
Good luck!
@hcharley what do you mean by “starting fresh” ? What exactly you did to make it work? I’m having the same issue and upgrading to v4.3 doesn’t solve it.