nestjs / docs.nestjs.com

The official documentation https://docs.nestjs.com 📕
MIT License
1.18k stars 1.69k forks source link

techniques/database section demo code could not run in production #89

Closed zhangbobell closed 6 years ago

zhangbobell commented 6 years ago

Here is the demo code in techniques/database section :

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

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'test',
      entities: [__dirname + '/../**/*.entity{.ts,.js}'],
      synchronize: true,
    }),
  ],
})
export class ApplicationModule {}

the entity configuration should be:

// delete the /.. 
entities: [__dirname + '/**/*.entity{.ts,.js}'],

delete ../ for purpose when run node dist/main.js, it will look for entity files from the root directory, and will find *.entity.ts files located in src, then it will cause buid failed such as

[Nest] 26420   - 2018-6-13 17:17:19   [TypeOrmModule] Unable to connect to the database. Retrying (1)... +1284ms

error stack shows: unexpected token import in xxx.entity.ts

NikitaIT commented 5 years ago

Solve this issue from nestjs mysql exemple project from github

Expected behavior

import { join } from 'path';
TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'test',
      entities: [join(__dirname, '**/**.entity{.ts,.js}')],
}

P.S. excuse me for this, but I had to write it here

vngrv commented 5 years ago

Solve this issue from nestjs mysql exemple project from github

Expected behavior

import { join } from 'path';
TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'test',
      entities: [join(__dirname, '**/**.entity{.ts,.js}')],
}

P.S. excuse me for this, but I had to write it here

its not workin if you have orm.config.ts in ./src/config/... or ./dist/config