Eve-Sama
Eve-Sama

Reputation: 2658

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

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

When I use npm run build, the cmd shows success. enter image description here

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.

enter image description here

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

What should I do next?

Upvotes: 0

Views: 2157

Answers (3)

hymair
hymair

Reputation: 216

You probably just need to add this in your tsconfig.json:

"paths": {
    "src/*": ["./src/*"]
}

TS can now correctly transform the src/ alias import when building the project.

Upvotes: 0

kamilg
kamilg

Reputation: 743

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

Upvotes: 2

Aleksandr Yatsenko
Aleksandr Yatsenko

Reputation: 869

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 { }

Upvotes: 2

Related Questions