侧边栏壁纸
博主头像
恪晨博主等级

前端程序员

  • 累计撰写 143 篇文章
  • 累计创建 41 个标签
  • 累计收到 17 条评论

目 录CONTENT

文章目录

Nestjs使用webpack-hmr与TypeOrmModule冲突问题

恪晨
2023-03-16 / 0 评论 / 1 点赞 / 117 阅读 / 103 字 / 正在检测是否收录...

使用webpack-hmr配置热加载后,与TypeOrmModule会产生冲突,无法读取entity文件配置,可以使用getMetadataArgsStorage引入即可。

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { getMetadataArgsStorage } from 'typeorm';

// The modules are loaded from here, hence importing the entities
import { AModule } from './a/a.module';
import { BModule } from './b/b.module';

@Module({
  imports: [
    AModule, 
    BModule, 
    TypeOrmModule.forRoot({ 
      ...,
      entities: getMetadataArgsStorage().tables.map(tbl => tbl.target),
      migrations: ...,
    }),
  ]
})
export class AppModule {}
1

评论区