Typescript 找不到模块';类变压器';或其相应的类型声明

Typescript 找不到模块';类变压器';或其相应的类型声明,typescript,nestjs,class-transformer,Typescript,Nestjs,Class Transformer,我正在尝试将类转换器包与NestJSV7一起使用。class transformer软件包与npm i class transformer--save一起安装。我已经按照你的指示去做了 这个包确实有一个typescript定义,我可以在我的文件系统上看到它(在node_模块内的正确目录中),VS代码可以导航到定义,所以我完全不明白它为什么不工作。我已尝试删除我的node_modules目录,清除我的NPM缓存,并使用NPM install重新安装所有内容 当我尝试编译时,我只得到而找不到模块'c

我正在尝试将类转换器包与NestJSV7一起使用。class transformer软件包与npm i class transformer--save一起安装。我已经按照你的指示去做了

这个包确实有一个typescript定义,我可以在我的文件系统上看到它(在node_模块内的正确目录中),VS代码可以导航到定义,所以我完全不明白它为什么不工作。我已尝试删除我的node_modules目录,清除我的NPM缓存,并使用
NPM install
重新安装所有内容

当我尝试编译时,我只得到
而找不到模块'class transformer'或其相应的类型声明。

我的实体代码:

import {
    Column,
    Entity,
    Index,
    OneToMany,
    PrimaryGeneratedColumn,
} from "typeorm";
import { Expose } from 'class-transformer';

@Entity("country", { schema: "my_schema" })
export class Country {
    @PrimaryGeneratedColumn({ type: "int", name: "id" })
    id: number;

    // Some properties here

    @Expose()
    get name(): string {
        return this.someProperty.content;
    }
    ...
}
My tsconfig.json:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": false,
    "outDir": "./dist",
  }
}
My package.js:

{
  "name": "project-name",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug 0.0.0.0:9229 --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nestjs/common": "^7.4.2",
    "@nestjs/config": "^0.5.0",
    "@nestjs/core": "^7.0.0",
    "@nestjs/platform-express": "^7.0.0",
    "@nestjs/typeorm": "^7.1.0",
    "class-transformer": "^0.3.1",
    "mysql": "^2.18.1",
    "rimraf": "^3.0.2",
    "rxjs": "^6.5.4",
    "typeorm": "^0.2.25"
  },
  "devDependencies": {
    "@nestjs/cli": "^7.0.0",
    "@nestjs/schematics": "^7.0.0",
    "@nestjs/testing": "^7.0.0",
    "@types/express": "^4.17.3",
    "@types/jest": "25.2.3",
    "@types/node": "^13.9.1",
    "@types/supertest": "^2.0.8",
    "@typescript-eslint/eslint-plugin": "3.0.2",
    "@typescript-eslint/parser": "3.0.2",
    "eslint": "7.2.0",
    "eslint-config-prettier": "^6.10.0",
    "eslint-plugin-import": "^2.20.1",
    "jest": "26.0.1",
    "prettier": "^1.19.1",
    "supertest": "^4.0.2",
    "ts-jest": "26.1.0",
    "ts-loader": "^6.2.1",
    "ts-node": "^8.6.2",
    "tsconfig-paths": "^3.9.0",
    "typescript": "^3.7.4"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

我花了两个令人沮丧的小时试图弄明白为什么会这样。这是我唯一遇到这种问题的软件包,从我的配置、软件包本身以及其他所有方面来看,这对我来说毫无意义。

什么报告了错误?正在运行tsc?运行
/node\u modules/.bin/tsc--noemit
时会发生什么?您好。运行
npm运行启动:dev
报告错误。它本质上是nest start的别名——watch。本文特别讨论了使用类转换器,这就是为什么我不理解为什么它不起作用的原因。明白了。我试图通过首先确定您安装的typescript是否可以找到该文件来确定哪个工具实际上无法解析该文件。这些工具相互委托。对不起,我没有注意到你答复的第二部分。运行
/node\u modules/.bin/tsc--noemit
不会返回错误。听起来nest没有使用
tsc
,这可能是一个配置问题,因为根据。尝试搭建一个新的空项目,看看有什么不同。我注意到的一点是,您没有指定
rootDir
,而是指定
outDir
。按照惯例,您的
rootDir
将是
src