[Troubleshooting] NestJS - EntityMetadataNotFoundError: No metadata 에러 해결

2023. 3. 31. 14:24나는 이렇게 학습한다/Framework

문제 상황

맥북에서는 잘 돌아갔던 코드가, 이상하게 윈도우에서만 돌아가지 않아서 며칠을 삽질함.

오류 내용은 다음과 같음

[Nest] 21720  - 2023. 03. 31. 오후 2:14:52   ERROR [ExceptionsHandler] No metadata for "detachedhouserent" was found.
EntityMetadataNotFoundError: No metadata for "detachedhouserent" was found.
    at DataSource.getMetadata (C:\Users\User\Desktop\github\rich-jinju\src\data-source\DataSource.ts:438:30)
    at Repository.get metadata [as metadata] (C:\Users\User\Desktop\github\rich-jinju\src\repository\Repository.ts:53:40)
    at Repository.find (C:\Users\User\Desktop\github\rich-jinju\src\repository\Repository.ts:524:39)
    at AppService.getPredictedAmountByArea (C:\Users\User\Desktop\github\rich-jinju\src\app.service.ts:28:59)
    at AppController.getAllHouses (C:\Users\User\Desktop\github\rich-jinju\src\app.controller.ts:15:42)
    at C:\Users\User\Desktop\github\rich-jinju\node_modules\@nestjs\core\router\router-execution-context.js:38:29
    at InterceptorsConsumer.intercept (C:\Users\User\Desktop\github\rich-jinju\node_modules\@nestjs\core\interceptors\interceptors-consumer.js:11:20)
    at C:\Users\User\Desktop\github\rich-jinju\node_modules\@nestjs\core\router\router-execution-context.js:46:60
    at C:\Users\User\Desktop\github\rich-jinju\node_modules\@nestjs\core\router\router-proxy.js:9:23
    at Layer.handle [as handle_request] (C:\Users\User\Desktop\github\rich-jinju\node_modules\express\lib\router\layer.js:95:5)

해결 방안

app.module.ts에서 autoLoadEntities를 활성화시켜준다.

autoLoadEntities는 TypeORM에서 제공하는 옵션 중 하나로, Entity 클래스들을 자동으로 로딩해 주는 역할을 한다.

imports: [UserModule,
  TypeOrmModule.forRoot({
    autoLoadEntities: true
  })
]

Reference

https://stackoverflow.com/questions/51562162/no-metadata-for-user-was-found-using-typeorm

반응형