在 service.ts 文件中进行更改时 Nest.js 中的编译问题
Compilation issues in Nest.js when changes made in a service.ts file
我正在做一个 Nest.js 项目并且
这就是我在 automobile.service.ts
中的内容
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Car } from './entities/car.entity';
import { Repository } from 'typeorm';
import { CreateAutoDto } from './dto/create-auto.dto';
import { UpdateAutoDto } from './dto/update-auto.dto';
export class AutoService {
constructor(
@InjectRepository(Car)
private autoRepository:Repository<Car>,
){}
create(createAutoDto: CreateAutoDto) {
return this.autoRepository.save(createAutoDto)
我现在面临的问题是,在终端输入nom run start:dev
后,日志就从这里停止:
[Nest] 234 - 10/10/2021, 7:36:53 PM [NestFactory] Starting Nest application...
[Nest] 234 - 10/10/2021, 7:36:54 PM [InstanceLoader] TypeOrmModule dependencies initialized +958ms
仅此而已,我无法在浏览器中打开该页面。但是,如果我有整个
constructor(
@InjectRepository(Car)
private autoRepository:Repository<Car>,
){}
内容已删除,代码编译无误。
[Nest] 101 - 10/10/2021, 7:05:57 PM [NestApplication] Nest application successfully started +3ms
我是 Nest.js 的新手。根本原因可能是什么?
编辑:
在 automobile.module.ts
import { AutoService } from './automobile.service';
import { AutoController } from './automobile.controller';
@Module({
controllers: [AutoController],
providers: [AutoService],
})
export class AutoModule {}
所以我做错的是在 automobile.module.ts
文件中,我忘记包含 imports: [TypeOrmModule.forFeature([Car])]
,这可能是导致数据库连接超时的根本原因。
我正在做一个 Nest.js 项目并且
这就是我在 automobile.service.ts
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Car } from './entities/car.entity';
import { Repository } from 'typeorm';
import { CreateAutoDto } from './dto/create-auto.dto';
import { UpdateAutoDto } from './dto/update-auto.dto';
export class AutoService {
constructor(
@InjectRepository(Car)
private autoRepository:Repository<Car>,
){}
create(createAutoDto: CreateAutoDto) {
return this.autoRepository.save(createAutoDto)
我现在面临的问题是,在终端输入nom run start:dev
后,日志就从这里停止:
[Nest] 234 - 10/10/2021, 7:36:53 PM [NestFactory] Starting Nest application...
[Nest] 234 - 10/10/2021, 7:36:54 PM [InstanceLoader] TypeOrmModule dependencies initialized +958ms
仅此而已,我无法在浏览器中打开该页面。但是,如果我有整个
constructor(
@InjectRepository(Car)
private autoRepository:Repository<Car>,
){}
内容已删除,代码编译无误。
[Nest] 101 - 10/10/2021, 7:05:57 PM [NestApplication] Nest application successfully started +3ms
我是 Nest.js 的新手。根本原因可能是什么?
编辑:
在 automobile.module.ts
import { AutoService } from './automobile.service';
import { AutoController } from './automobile.controller';
@Module({
controllers: [AutoController],
providers: [AutoService],
})
export class AutoModule {}
所以我做错的是在 automobile.module.ts
文件中,我忘记包含 imports: [TypeOrmModule.forFeature([Car])]
,这可能是导致数据库连接超时的根本原因。