Typeormを導入してよくわからないエラーが発生しました。

解決策:

import {Module} from '@nestjs/common';
import {AppController} from './app.controller';
import {AppService} from './app.service';
import {ItemService} from './services/item.service';
import {ItemController} from './controllers/item.controller';
import {TypeOrmModule} from '@nestjs/typeorm';
import {Item} from './entities/item.entity';

@Module({
  imports: [
    TypeOrmModule.forFeature([Item]),
    TypeOrmModule.forRoot({
      type: 'sqlite',
      database: 'db/typeorm-test',
      synchronize: true,
      entities: [Item]})], // <= これも大丈夫
     //entities: ['dist/**/*.entity.js']})], <= これも大丈夫
      //entities: ['src/entities/*.entity.ts' ]})], <= これだとエラー出る
  controllers: [AppController, ItemController],
  providers: [AppService, ItemService],
})
export class AppModule {
}

指定方法によってエラーが出るみたいですので、distでいくかentityを指定するといいみたいです。

参考記事

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

コメントをどうぞ

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA