typescript Nest无法解析TypeOrmCoreModule的依赖项

vyswwuz2  于 2023-01-03  发布在  TypeScript
关注(0)|答案(2)|浏览(613)

源代码/联系人/联系人.模块.ts

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ContactController } from './contact.controller';
import { Contact } from './contact.entity';
import { ContactRepository } from './contact.repo';
import { ContactService } from './contact.service';

@Module({
  imports: [
     TypeOrmModule.forFeature([
      Contact,
    ]), 
  ],
  controllers: [ContactController],
  providers: [ContactService, ContactRepository],
})
export class ContactModule {}

源代码/应用程序模块.ts

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { getMetadataArgsStorage } from 'typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ContactModule } from './contact/contact.module';

@Module({
  imports: [
   TypeOrmModule.forRoot({
      type: 'sqlite',
      database: 'db',
      entities: getMetadataArgsStorage().tables.map(tbl => tbl.target),
      synchronize: true,
    }), 
    ContactModule
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

npm新开始:开发人员

给予这样的错误,我试图找到可能在互联网上的每一个解决方案,但我不知道我犯了什么错误,我得到了这样的错误。

嵌套-v(8.1.6)

ERROR [ExceptionHandler] Nest can't resolve dependencies of the TypeOrmCoreModule (TypeOrmModuleOptions, ?). Please make sure that the argument ModuleRef at index [1] is available in the TypeOrmCoreModule context.

Potential solutions:
- If ModuleRef is a provider, is it part of the current TypeOrmCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within TypeOrmCoreModule?
  @Module({
    imports: [ /* the Module containing ModuleRef */ ]
  })
72qzrwbm

72qzrwbm1#

我遇到这个问题是因为typeorm的安装不好。
对我有效:
1-删除节点_模块
2-运行npm i
3-在我的项目中再次运行npm install --save @nestjs/typeorm typeorm mysql2

xe55xuns

xe55xuns2#

当我从全局可用的ConfigService切换到自定义的EnvConfigService时,我遇到了TypeOrmCoreModule的错误。在这种情况下,例如,我需要import自定义的EnvConfigService所在的模块;如以下黑体字所示:

const typeOrmModule = TypeOrmModule.forRootAsync({
      imports: [EnvConfigModule],
      inject: [EnvConfigService],
      useFactory: (config: EnvConfigService) => {
        return {
          type: 'postgres',
          host: config.postgresHost,
          port: config.postgresPort,
          database: config.postgresDatabaseName,
          username: config.postgresUsername,
          password: config.postgresPassword,
          synchronize: true,
          entities: [User, PasswordRecovery]
        }
      }
    })

当我注入ConfigService时,不需要import语句,因为它是全局可访问的。

相关问题