TypeScript:模块“@nestjs/typeorm”没有导出成员“TypeOrmModule”是什么原因导致的?

问题描述 投票:0回答:4

我已经安装了所有必要的软件包来为我的 mysql 数据库使用 typeorm,但我不断收到

Module '"@nestjs/typeorm"' has no exported member 'TypeOrmModule'.
当我启动服务器时。 为什么?

这是 package.json 文件中我的开发依赖项。

dependencies": {
    "@nestjs/common": "^8.0.0",
    "@nestjs/config": "^1.0.1",
    "@nestjs/core": "^8.0.0",
    "@nestjs/platform-express": "^8.0.0",
    "@nestjs/typeorm": "github:nestjs/typeorm",
    "mysql": "^2.18.1",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0",
    "typeorm": "^0.2.37"
  },

这是我的database.module.ts 文件,我应该在其中使用TypeOrmModule。

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

@Module({
  imports: [TypeOrmModule.forRoot()],
  exports: [TypeOrmModule],
})
export class DatabaseModule {
  constructor(connection: Connection) {
    if (connection.isConnected) console.log('connected successfully!');
  }
}

我再次运行 npm install 以查看它是否可以修复它,但我仍然遇到相同的错误。有谁知道出了什么问题吗?

typescript nestjs typeorm
4个回答
0
投票

事实证明这是我的

database.module.ts
文件中的层次结构问题。 TypeOrmModule 应该位于 Nestjs 的父模块下才能被识别。 TypeScript 在这方面是严格的。

本来应该是这样的:

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

不是这个:

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

我希望这能解决任何面临同样问题的人,因为它对我来说就是这样。


0
投票

我只是尝试在 TypeORM find({}) 方法中使用 Like,

import { Like } from '@nestjs/typeorm';   
    this.bugRepository.find({
        verson: Like(`%${query.version}`)
  });

0
投票

在某些情况下,重新启动 TypeScript 服务器可以解决问题。

“ctrl + shift + p”并选择“TypeScript:重新启动 TS Server”

如何在“vscode”中重启 Typescript 服务器


0
投票

对我来说,它是通过使用 npm 或yarn(无论你使用什么)卸载和安装 @nestjs/typeorm 来工作的:

npm remove @nestjs/typeorm

然后

npm install @nestjs/typeorm
© www.soinside.com 2019 - 2024. All rights reserved.