TypeORM Entity in NESTJS - Cannot use import statement outside a module

后端 未结 10 1830
甜味超标
甜味超标 2020-12-03 10:01

Started new project with \'nest new\' command. Works fine until I add entity file to it.

Got following error:

import { Entity, Column, Primary

10条回答
  •  我在风中等你
    2020-12-03 10:41

    I was using Node.js with Typescript and TypeORM when I faced this issue. Configuring in ormconfig.json file worked for me.

    entities: ['dist/**/*.entity.js']
    

    My full code of ormconfig.json file:

    {
      "type": "mysql",
      "host": "localhost",
      "port": 3306,
      "username": "xxxxxxxx",
      "password": "xxxxxxxx",
      "database": "typescript_orm",
      "synchronize": true,
      "logging": false,
      "migrationTableName": "migrations",
      "entities": [
        "dist/**/*.entity.js"
      ],
      "migrations": [
        "src/migration/**/*.{ts, js}"
      ],
      "suscribers": [
        "src/suscriber/**/*.{ts, js}"
      ],
      "cli": {
        "entitiesDir": "src/model",
        "migrationDir": "src/migration",
        "suscribersDir": "src/suscriber"
      }
    }
    

提交回复
热议问题