SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.25k stars 664 forks source link

[Bug]: NoResourceAdapterError: There are no adapters supporting one of the resource you provided #1688

Closed behruzrahimov closed 2 months ago

behruzrahimov commented 3 months ago

Contact Details

No response

What happened?

When starting the application with AdminJS integrated, an error occurs: NoResourceAdapterError: There are no adapters supporting one of the resource you provided. This error is thrown when attempting to use TypeORM entities with AdminJS.

I expected AdminJS to recognize and use the TypeORM entities without throwing an error, allowing me to manage the entities through the AdminJS interface.

Bug prevalence

This bug occurs every time the application is started.

AdminJS dependencies version

Here is a list of the relevant dependencies from package.json:


    "adminjs": "7.8.7",
    "@adminjs/nestjs": "6.1.0",
    "@adminjs/express": "6.1.0",
 "dependencies": {
    "@nestjs/common": "^10.3.8",
    "@nestjs/config": "^3.2.2",
    "@nestjs/core": "^10.3.8",
    "@nestjs/platform-express": "^10.3.8",
    "@nestjs/swagger": "^7.4.0",
    "dotenv": "^16.4.5",
    "jsonwebtoken": "^9.0.2",
    "pg": "^8.11.5",
    "typeorm": "^0.3.20",
    "uuid": "^9.0.1",
    "class-validator": "^0.14.1",
    "class-transformer": "^0.5.1",
    "adminjs": "7.8.7",
    "@adminjs/nestjs": "6.1.0",
    "@adminjs/express": "6.1.0",
    "express-session": "1.18.0",
    "express-formidable": "1.2.0",
    "@adminjs/sql": "2.2.6",
    "@babel/plugin-syntax-import-assertions": "7.24.7",
    "@adminjs/typeorm": "5.0.1",
    "body-parser": "1.20.2"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.3.2",
    "@nestjs/schematics": "^10.1.1",
    "@nestjs/testing": "^10.3.8",
    "@types/express": "^4.17.21",
    "@types/jest": "^29.5.12",
    "@types/jsonwebtoken": "^9.0.6",
    "@types/multer": "^1.4.11",
    "@types/node": "^20.12.12",
    "@types/supertest": "^6.0.2",
    "@types/uuid": "^9.0.8",
    "@typescript-eslint/eslint-plugin": "^6.21.0",
    "@typescript-eslint/parser": "^6.21.0",
    "jest": "^29.7.0",
    "prettier": "^3.3.2",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.4",
    "ts-jest": "^29.1.2",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.2",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.4.5",
    "@types/body-parser": "1.19.5"
  }

What browsers do you see the problem on?

Chrome

Relevant log output

file:///project/node_modules/.pnpm/adminjs@7.8.7_@types+babel__core@7.20.5_@types+react@18.3.3/node_modules/adminjs/lib/backend/utils/resources-factory/resources-factory.js:73
        throw new NoResourceAdapterError(resourceObject);
              ^

NoResourceAdapterError: There are no adapters supporting one of the resource you provided
    at file:///project/node_modules/.pnpm/adminjs@7.8.7_@types+babel__core@7.20.5_@types+react@18.3.3/node_modules/adminjs/lib/backend/utils/resources-factory/resources-factory.js:73:15
    at Array.map (<anonymous>)
    at ResourcesFactory._convertResources (file:///project/node_modules/.pnpm/adminjs@7.8.7_@types+babel__core@7.20.5_@types+react@18.3.3/node_modules/adminjs/lib/backend/utils/resources-factory/resources-factory.js:68:22)
    at ResourcesFactory.buildResources (file:///project/node_modules/.pnpm/adminjs@7.8.7_@types+babel__core@7.20.5_@types+react@18.3.3/node_modules/adminjs/lib/backend/utils/resources-factory/resources-factory.js:28:35)
    at new AdminJS (file:///project/node_modules/.pnpm/adminjs@7.8.7_@types+babel__core@7.20.5_@types+react@18.3.3/node_modules/adminjs/lib/adminjs.js:79:39)
    at AdminModule.onModuleInit (file:///project/node_modules/.pnpm/@adminjs+nestjs@6.1.0_@nestjs+common@10.3.10_class-transformer@0.5.1_class-validator@0.14.1_r_qveeu3yzi3vkc6zsjdlix6dbiu/node_modules/@adminjs/nestjs/build/admin.module.js:70:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async callModuleInitHook (/project/node_modules/.pnpm/@nestjs+core@10.3.10_@nestjs+common@10.3.10_class-transformer@0.5.1_class-validator@0.14.1_re_mxy2umldb5kjaz5pxuunqqkrty/node_modules/@nestjs/core/hooks/on-module-init.hook.js:51:9)
    at async NestApplication.callInitHook (project/node_modules/.pnpm/@nestjs+core@10.3.10_@nestjs+common@10.3.10_class-transformer@0.5.1_class-validator@0.14.1_re_mxy2umldb5kjaz5pxuunqqkrty/node_modules/@nestjs/core/nest-application-context.js:223:13)
    at async NestApplication.init (project/node_modules/.pnpm/@nestjs+core@10.3.10_@nestjs+common@10.3.10_class-transformer@0.5.1_class-validator@0.14.1_re_mxy2umldb5kjaz5pxuunqqkrty/node_modules/@nestjs/core/nest-application.js:100:9) {
  resource: [Module: null prototype] {
    UserEntity: EntitySchema {
      options: {
        name: 'UserEntity',
        tableName: 'users',
        columns: {
          id: {
            type: 'uuid',
            primary: true,
            generated: 'uuid',
            unique: true
          },
          name: { type: 'varchar' },
          surname: { type: 'varchar' },
          patronymic: { type: 'varchar', nullable: true },
          gender: { type: 'enum', enum: [Array] },
          age: { type: 'int', nullable: true },
          district: { type: 'varchar', nullable: true },
          role: { type: 'enum', enum: [Array] },
          school: { type: 'varchar', nullable: true },
          email: { type: 'varchar' },
          password: { type: 'varchar' },
          createdAt: { type: 'timestamp', createDate: true },
          deletedAt: { type: 'timestamp', deleteDate: true, nullable: true }
        }
      },
      '@instanceof': Symbol(EntitySchema)
    }
  }
}

### Relevant code that's giving you issues

```TypeScript
1.AdminJS options configuration:

import { AdminJSOptions } from 'adminjs';
import { UserEntity } from '../_db/entity/UserEntity';
import componentLoader from './component-loader.js';

const options: AdminJSOptions = {
  componentLoader,
  rootPath: '/admin',
  resources: [
    {
      resource: UserEntity,
      options: {
        // Customize AdminJS options for the resource here
      },
    },
  ],
};

export default options;

Main NestJS application bootstrap:

import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ModuleApp } from './app/module.app.js';
import { AppDataSource } from './app/globals.app.js';
import * as AdminJSTypeorm from '@adminjs/typeorm';
import AdminJS from 'adminjs';

async function bootstrap() {
  const app = await NestFactory.create(ModuleApp, { cors: true });

  // Register the TypeORM adapter
  AdminJS.registerAdapter(AdminJSTypeorm);

  await AppDataSource.initialize();
  const config = new DocumentBuilder()
    .setTitle('Career API')
    .setDescription('The Career API documentation')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('swagger', app, document);
  await app.listen(8000);
}

bootstrap().then(() => console.log('Server started on http://localhost:8000/'));

app module

import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import * as controllers from '../controller/_index.js';
import { AuthMiddleware } from '../middleware/_index.js';
import * as providers from '../service/_index.js';
import { AdminModule } from '@adminjs/nestjs';
import { ConfigModule } from '@nestjs/config';
import options from '../admin/options.js';
import provider from '../admin/auth-provider.js';
import * as dotenv from 'dotenv';
dotenv.config();
@Module({
  imports: [
    ConfigModule.forRoot({
      envFilePath: '.env',
    }),

    AdminModule.createAdminAsync({
      useFactory: () => ({
        adminJsOptions: options,
        auth: {
          provider,
          cookiePassword: process.env.COOKIE_SECRET!,
          cookieName: 'adminjs',
        },
        sessionOptions: {
          resave: true,
          saveUninitialized: true,
          secret: process.env.COOKIE_SECRET!,
        },
      }),
    }),
  ],
  controllers: Object.values(controllers),
  providers: Object.values(providers),
})
export class ModuleApp implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(AuthMiddleware).forRoutes('/12345');
  }
}
dziraf commented 3 months ago

EntitySchema is not supported, @adminjs/typeorm only works with classes that extend BaseEntity