TypeORM Entity in NESTJS - Cannot use import statement outside a module

后端 未结 10 1802
甜味超标
甜味超标 2020-12-03 10:01

Started new project with \'nest new\' command. Works fine until I add entity file to it.

Got following error:

import { Entity, Column, Primary

10条回答
  •  一整个雨季
    2020-12-03 10:29

    You need to have a something.module.ts for every section of your app. It works like Angular. This is setup with GraphQL resolvers and service. REST is a bit different with a controller. Each module will probably have an entity and if GraphQL, projects.schema.graphql.

    projects.module.ts

    import { Module } from '@nestjs/common';
    import { TypeOrmModule } from '@nestjs/typeorm';
    import { ProjectsService } from './projects.service';
    import { Projects } from './projects.entity';
    
    import { ProjectsResolvers } from './projects.resolvers';
    
    @Module({
      imports: [
        TypeOrmModule.forFeature([Projects])],
      providers: [
        ProjectsService,
        ProjectsResolvers
      ],
    
    })
    
    export class ProjectsModule {}
    

提交回复
热议问题