Background
Break News
How to add local font to Tailwind Css and NextJS? - Tutorial Design Pattern? - Blockchain Technology, How to create own Bitcoin virtual currency - Zustand mordern management state - Design Pattern - Flyweight Pattern? - Docker Full training Topic

[Solved] "Object literal may only specify known properties, and cli does not exist in type TypeOrmModuleOptions"

Thursday 13 October 2022
|
Read: Completed in minutes

[Solved] "Object literal may only specify known properties, and cli does not exist in type TypeOrmModuleOptions"

✋✋✋Hello everyone, welcome back to Learn Tech Tips Blogspot. I am Zidane (大家好, 我是雞蛋🥚🥚) 

Object literal may only specify known properties, and 'cli' does not exist in type TypeOrmModuleOptions

This topic is focus on NestJS developer, who is working with NestJS and TypeORM and special update TypeORM to version 0.3.x 

package.json

Object literal may only specify known properties, and 'cli' does not exist in type TypeOrmModuleOptions


Because of many people got stuck on TypeORM after update to version 0.3.x (this update from May 2022) and until now so less resource talking about this issue, I had found many solution and finally I have a solution for migration now, so i want to share with you how to solved successfully in below way. Save this articles and share to NestJS use TypeORM 0.3.x developer for they can easy do it too.

If you use typeorm 0.3.x, typeorm-cli needs migration path as a command option now, don't support cli on TypeOrmModuleOptions anymore.

Ok. Let's back to topic


So you can do this on command like that

Typeorm: 0.2.x

          
export const connectionSource = new DataSource({
    migrationsTableName: 'migrations',
    type: 'postgres',
    host: 'localhost',
    port: 55432,
    username: 'postgres',
    password: '123456',
    database: 'todolist',
    entities: ['src/**/entity/*.entity.ts'],         
    cli: {
        migrationDirs: ['src/migrations/*.ts'],
    }
    extra: {
        charset: 'utf8mb4_unicode_ci',
    },
    synchronize: false,
    logging: true,  
    migrations: ['src/migrations/*.ts'],
    subscribers: ['src/subscriber/**/*{.ts,.js}'],  
});      

Typeorm: 0.3.x (should remove cli) ./configORM.ts

         
export const connectionSource = new DataSource({
    migrationsTableName: 'migrations',
    type: 'postgres',
    host: 'localhost',
    port: 55432,
    username: 'postgres',
    password: '123456',
    database: 'todolist',
    entities: ['src/**/entity/*.entity.ts'],     
    extra: {
        charset: 'utf8mb4_unicode_ci',
    },
    synchronize: false,
    logging: true,  
    migrations: ['src/migrations/*.ts'],
    subscribers: ['src/subscriber/**/*{.ts,.js}'],  
});

package.json - Typeorm: 0.3.x 

         
"typeorm": "typeorm-ts-node-commonjs -d ./configORM.ts",
       

So when use command (Typeorm 0.3.x), you should add the path like below command

npm run typeorm migration:generate src/migrations/Init

I explain a little more:

entities: ['src/**/entity/*.entity.ts'], 

This entities will map with current structure: 

src/users/entity/users.entity.ts

src/roles/entity/roles.entity.ts

src/permissions/entity/permissions.entity.ts

Object literal may only specify known properties, and 'cli' does not exist in type TypeOrmModuleOptions

migrations: ['src/migrations/*.ts'],

And this migrations folder on location src/migrations/*.ts 

Object literal may only specify known properties, and 'cli' does not exist in type TypeOrmModuleOptions

Please be carefully on the location, if you cannot run migration (No migrations are pending) by command: npm run typeorm generation:run, that maybe your location for migrations folder is not correct.

Another noted is your path on each entiry must be a relative path, normally when you import  when use below link: /src/users/entity/users.entity. But this unluckily will catch an error when you run migration, for sure on run migration succeed. You must change your path to relative like below screenshot.

the correct is:./../../users/entity/users.entity

Object literal may only specify known properties, and 'cli' does not exist in type TypeOrmModuleOptions - Learn Tech Tips

Add command into package.json
 "scripts": {
      ...
      "typeorm": "typeorm-ts-node-commonjs -d ./configORM.ts", 
      "migration:generate": "npm run typeorm migration:generate",
      "migration:run": "npm run typeorm migration:run", 
      "migration:revert": "npm run typeorm migration:revert" 
},
configORM.ts must put on root folder so the below folder can point to folder correctly
         
entities: ['src/**/entity/*.entity.ts'],     
migrations: ['src/migrations/*.ts'],
subscribers: ['src/subscriber/**/*{.ts,.js}'],  

👌Ok, That's all message I want to share with you, this issue had taken me a few hours, I don't want to you waste time like me, so I had shared all around issue for typeorm 0.3.x nestjs now for your reference, save this articles I think you will use it on the furture soon, I am Zidane. ✊

Thanks for reading. I hope this helps. Feel free to ask back any questions and let us know how it goes, I will keep working with you until it's resolved.
✋✋✋✋ Webzone Tech Tips - I am Zidane, See you next time



🙇🏼 We Appreciate Your Comments and Suggestions - Webzone - all things Tech Tips web development 🙇🏼
Popular Webzone Tech Tips topic maybe you will be like it - by Webzone Tech Tips - Zidane
As a student, I found Blogspot very useful when I joined in 2014. I have been a developer for years . To give back and share what I learned, I started Webzone, a blog with tech tips. You can also search for tech tips zidane on Google and find my helpful posts. Love you all,

I am glad you visited my blog. I hope you find it useful for learning tech tips and webzone tricks. If you have any technical issues, feel free to browse my posts and see if they can help you solve them. You can also leave a comment or contact me if you need more assistance. Here is my blog address: https://learn-tech-tips.blogspot.com.

My blog where I share my passion for web development, webzone design, and tech tips. You will find tutorials on how to build websites from scratch, using hot trends frameworks like nestjs, nextjs, cakephp, devops, docker, and more. You will also learn how to fix common bugs on development, like a mini stackoverflow. Plus, you will discover how to easily learn programming languages such as PHP (CAKEPHP, LARAVEL), C#, C++, Web(HTML, CSS, javascript), and other useful things like Office (Excel, Photoshop). I hope you enjoy my blog and find it helpful for your projects. :)

Thanks and Best Regards!
Follow me on Tiktok @learntechtips and send me a direct message. I will be happy to chat with you.
Webzone - Zidane (huuvi168@gmail.com)
I'm developer, I like code, I like to learn new technology and want to be friend with people for learn each other
I'm a developer who loves coding, learning new technologies, and making friends with people who share the same passion. I have been a full stack developer since 2015, with more than years of experience in web development.
Copyright @2022(November) Version 1.0.0 - By Webzone, all things Tech Tips for Web Development Zidane
https://learn-tech-tips.blogspot.com