0

src/contact/contact.module.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 {}

src/app.module.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 */ ]
  })
4

1 回答 1

0

由于 typeorm 安装错误,我遇到了这个问题。

为我工作:

1- 删除 node_module
2- 运行npm i
3- 在npm install --save @nestjs/typeorm typeorm mysql2我的项目中再次运行。

于 2022-02-07T23:00:54.750 回答