我正在使用Nest.js
+ TypeORM
进行开发并尝试在计算机中进行部署。
我可以在develop mode
中连接到mysql,但是在product mode
中却失败了。
下面是我的TypeORM配置。
@Module({
imports: [
AuthModule,
ClassificationModule,
ArticleModule,
UserModule,
CommentModule,
FragmentModule,
TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
// logging: ["query"],
port: 3306,
username: 'root',
password: '123456',
database: 'myblog',
entities: ['src/**/**.entity{.ts,.js}'],
synchronize: true
})
]
})
export class AppModule { }
在develop mode
中,它可以成功连接到mysql。
但是在product mode
中,它显示无法连接mysql。
答案 0 :(得分:3)
ts-node
在内存中管理您的打字稿编译,并在内部处理从src
到dist
的引用更改。但是,当您开始运行纯node
变体时,这是一个问题,因为您将位于dist
目录中,而不是src
中,因此TypeORM将无法找到具有已定义实体数组的实体。相反,您应该使用entities: [join(__dirname, '/**/*.entity.{js,ts}')],
来允许在ts和js之间动态更改,因此您不必担心运行的是什么。
我还建议使用tsc-watch
进行开发,因为默认情况下它将在成功编译时运行node
,而您不必担心ts-node
的内存消耗。