Cover image for Solve Nestjs TypeORM entity import problem

Solve Nestjs TypeORM entity import problem

nikhilshisode profile image Nikhil Shisode Updated on ・1 min read

Version 6 of Nest js has introduced some new features in cli. This cli performs many tasks properly. However it has also introduced some new problems. One of which is TypeORM entity not registered problem. Until Nestjs community fixes this issue there is work around I have found.

This blog is written to solve following error-

[0] import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
[0]        ^
[0] SyntaxError: Unexpected token {

You can use previous version (5) of Nestjs cli but if you don't want to then follow following instructions-

For database connection using TypeORM- use nodemon config and update start, start:dev, and start:debug scripts.

create nodemon.json with following content

  "watch": ["src"],
  "ext": "ts",
  "ignore": ["src/**/*.spec.ts"],
  "exec": "ts-node -r tsconfig-paths/register src/main.ts"

create nodemon-debug.json with following content

  "watch": ["src"],
  "ext": "ts",
  "ignore": ["src/**/*.spec.ts"],
  "exec": "node --inspect-brk -r ts-node/register -r tsconfig-paths/register src/main.ts"

npm scripts required-

"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "nodemon",
"start:debug": "nodemon --config nodemon-debug.json",

I hope your problem has fixed and you can perform table creation using TypeORM entities in Nestjs.

This post was originally written for TechNix Blog

Posted on by:

nikhilshisode profile

Nikhil Shisode


Computer engineer seeking to use proven experience of software development technologies, tools, and best practices to meet business needs.


markdown guide

Very Good.
My problem was resolved.