Home > OS >  Can't create migrations using MikroORM and NestJS
Can't create migrations using MikroORM and NestJS

Time:11-19

Unable to create migrations, or any other MikroORM CLI command, due to an unexpected error with the configuration file.

This is the current versions of MikroORM and NestJS being used on my package.json

"@mikro-orm/core": "^5.5.3",
"@mikro-orm/mysql": "^5.5.3",
"@mikro-orm/nestjs": "^5.1.2",
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@mikro-orm/cli": "^5.5.3",
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"ts-node": "^10.9.1",

The MikroORM CLI was configured in the package.json to use ts-node, according to the official documentation

"mikro-orm": {
  "useTsNode": true,
  "configPaths": [
    "./src/config/mikro-orm.config.ts",
    "./dist/config/mikro-orm.config.js"
  ]
}

And this is my mikro-orm-config.ts file

export const mikroOrmConfig: Options = {
  type: 'mysql',
  host: '127.0.0.1',
  port: 3306,
  dbName: 'market_store',
  user: 'root',
  password: 'admin',
  entities: ['dist/**/*.entity.js'],
  entitiesTs: ['src/**/*.entity.ts'],
  migrations: {
    path: 'dist/migrations',
    pathTs: 'src/migrations',
  },
};

As you can see, the type was specified, but when I run any MikroORM CLI command I get the following error displayed

Error: No platform type specified, please fill in `type` or provide custom driver class in `driver` option. Available platforms types: [
  'mongo',
  'mysql',
  'mariadb',
  'postgresql',
  'sqlite',
  'better-sqlite'
]

The following is the output of my npx mikro-orm debug command

Current MikroORM CLI configuration
 - dependencies:    
   - mikro-orm 5.5.3
   - node 18.12.1   
   - typescript 4.9.3
 - package.json found                                                                              
 - ts-node enabled                                                                                 
 - searched config paths:                                                                          
   - C:/Users/DanielMendesSechisnk/Projects/nestjs-rest-api/src/config/mikro-orm.config.ts (found) 
   - C:/Users/DanielMendesSechisnk/Projects/nestjs-rest-api/dist/config/mikro-orm.config.js (found)
   - C:/Users/DanielMendesSechisnk/Projects/nestjs-rest-api/src/mikro-orm.config.ts (not found)    
   - C:/Users/DanielMendesSechisnk/Projects/nestjs-rest-api/mikro-orm.config.ts (not found)        
   - C:/Users/DanielMendesSechisnk/Projects/nestjs-rest-api/dist/mikro-orm.config.js (not found)   
   - C:/Users/DanielMendesSechisnk/Projects/nestjs-rest-api/mikro-orm.config.js (not found)        
- configuration not found (No platform type specified, please fill in `type` or provide custom driver class in `driver` option. Available platforms types: [
  'mongo',
  'mysql',
  'mariadb',
  'postgresql',
  'sqlite',
  'better-sqlite'
])

I created my entities manually on my database to see if the app was able to connect to the database outside of the MikroORM CLI, and it succeeded, I was able to to do several CRUD operations on my database, with it correctly being updated.

I even tried to use a lower version of MikroORM, like 5.0.3, since the official documentation has a working example using it, but the same error persisted.

What am I missing?

CodePudding user response:

Use default export in your config file.

  • Related