NodeJS 无法在express、typescript、typeorm中找到模块

5kgi1eie  于 2023-03-01  发布在  Node.js
关注(0)|答案(1)|浏览(179)

我用的是express + typeorm + typescript。
我得到的错误是这样的

CustomError: Cannot find module 'server/src/entity/user.entity' imported server/src/app.ts

它无法仅找到模块用户.entity.ts,但可以找到模块另一个.ts文件。
app.ts

import { User } from './entity/user.entity';

user.entity.ts

import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"

@Entity()
export class User {
    @PrimaryGeneratedColumn()
    id: number

    @Column()
    firstName: string

    @Column()
    lastName: string
}

tsconfing.json

{
  "compilerOptions": {
    "module": "ESNext",
    "esModuleInterop": true,
    "target": "ESNext",
    "moduleResolution": "Node",
    "outDir": "dist",
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "isolatedModules": false,
    "strict": true,
    "noImplicitAny": true,
    "experimentalDecorators": true,
    "inlineSourceMap": true,
    "strictPropertyInitialization": false
  },
  "ts-node": {
      "esm": true
  },
  "lib": ["esnext"]
}

为什么找不到用户。实体。ts...请帮帮我...!!!!!!!!

相关问题