@admin-bro/nestjs with @admin-bro/sequelize and mysql ? Getting Error NoResourceAdapterError

554 Views Asked by At

Facing same issue with '@admin-bro/sequelize' NoResourceAdapterError: There are no adapters supporting one of the resource you provided

import { Database, Resource } from '@admin-bro/sequelize';
import { AdminModule } from '@admin-bro/nestjs';
AdminBro.registerAdapter({ Database, Resource });


SequelizeModule.forRoot({
      dialect: 'mysql',
      host: process.env.DATABASE_HOST,
      port: +process.env.DATABASE_PORT,
      username: process.env.DATABASE_USERNAME,
      password: process.env.DATABASE_PASSWORD,
      database: process.env.DATABASE_NAME,
      models: [__dirname + '/**/*.model.ts'],
      logging: console.log
    }),


    AdminModule.createAdmin({ adminBroOptions: { rootPath: '/admin', resources: [{ resource: User, options: {} }], } }),


@Table({
  modelName: 'user',
  timestamps: false
})
export class User extends Model {
}
2

There are 2 best solutions below

0
On

I have solved this by adding the following code at the top level of my app.module.ts just after all my importations :

(async () => {
  const AdminJSSequelize = await import('@adminjs/sequelize');
  const AdminJS = (await import('adminjs')).AdminJS;
  AdminJS.registerAdapter({
    Resource: AdminJSSequelize.Resource,
    Database: AdminJSSequelize.Database,
  });
})();
0
On

This case can be fixed by below answer. It was an issue that the entity had to extends 'BaseEntity' to use it in admin bro.

AdminBro - NoResourceAdapterError