Why Nest.js throw a error when run main.js?

馋奶兔 提交于 2019-12-11 17:12:16

问题


I am using Nest.js to develop a web backend.

When I use npm run build, the cmd shows success.

But when I use node dist/main.js, the cmd shows error. But I'm sure this file exist and in develop mode (npm run start), everything's ok.

This is github address. https://github.com/Eve-1995/Oreo/tree/master/oreo-back-end

What should I do next?


回答1:


entities: [__dirname + '/../**/**/!(*.d).entity.{ts,js}'], is doing the trick for me both in production and dev envs.




回答2:


I think the reason is in TypeOrm config.

@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}'], // <-- replace it to 'dist/**/**.entity.js' in prod mode or use relative path
      synchronize: true,
    }),
  ],
})
export class AppModule { }


来源:https://stackoverflow.com/questions/57944941/why-nest-js-throw-a-error-when-run-main-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!