【问题标题】:Compilation issues in Nest.js when changes made in a service.ts file在 service.ts 文件中进行更改时 Nest.js 中的编译问题
【发布时间】:2021-11-29 18:27:46
【问题描述】:

我正在开发一个 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 {}

【问题讨论】:

  • 数据库连接问题,可能
  • 我认为我们需要了解更多关于这里发生的事情的背景信息。如果删除 @InjectRepostory() 使其正常工作,那么在 Nest 的解决方案下似乎有一个未捕获的异常。你能显示你的相关automobile.module.ts文件吗?
  • 我刚刚从automobile.module.ts添加了代码
  • k,我知道问题出在哪里了
  • 我想说这很可能是由上面@MicaelLevi 提到的数据库连接超时引起的。它可能需要很长时间才会抛出,这会让你认为“什么都没有发生”。

标签: javascript typescript nestjs


【解决方案1】:

所以我做错的是在automobile.module.ts 文件中,我忘记包含imports: [TypeOrmModule.forFeature([Car])],这可能是导致数据库连接超时的根本原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    • 2023-02-10
    • 2012-09-25
    相关资源
    最近更新 更多