SyntaxError: Unexpected token import typeORM entity

You can also use ts-node to run typeorm, which will allow you to run ts files, and which will allow you to avoid compiling and running separate js files.

Per this github comment, you can do the following:

1.- Install ts-node and typescript globally:

$ npm install -g ts-node typescript

2.- Execute the typeorm command with ts-node:

$ ts-node ./node_modules/.bin/typeorm migrations:generate -n

If you're on windows, you'll have problems with that. Per this comment, you'll want to directly reference cli.js:

ts-node node_modules\typeorm\cli.js


Alright, I am simply dumb.

So, the ormconfig.json points your entities to your ts files in your /src folder. When you build your project, it should point to where your entities are. I did think it was odd that it was trying to reference a TS file after building.

ormconfig.json

{
   "type": "postgres",
   "host": "**********************",
   "port": 5432,
   "username": "**************",
   "password": "*************",
   "database": "*************",
   "synchronize": true,
   "logging": false,
   "entities": [
      // changed this

      "dist/entity/*.js"
   ],
   "migrations": [
      "src/migration/**/*.ts"
   ],
   "subscribers": [
      "src/subscriber/**/*.ts"
   ],
   "cli": {
      "entitiesDir": "src/entity",
      "migrationsDir": "src/migration",
      "subscribersDir": "src/subscriber"
   }
}

it happened to me too, the problem occurred because i've accidently imported 'BaseEntity' from 'typeorm/browser' instead of 'typeorm'.

the first one is js file, and the second is ts file.