Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledPromiseRejectionWarning: NoResourceAdapterError: There are no adapters supporting one of the resource you provided #14

Open
JamshedLatipov opened this issue Jun 30, 2020 · 13 comments

Comments

@JamshedLatipov
Copy link

JamshedLatipov commented Jun 30, 2020

Good day! Please help, i have installed every dependencies and i don't understand why i get "no adapters" error.
As i understand admin-bro-typescript is adapter.

Thanks!

import { Database, Resource } from "admin-bro-typeorm";
import AdminBro from "admin-bro";
import AdminBroExpress from "admin-bro-expressjs";
import express from "express";

import { createConnection } from "typeorm";
import { Blog } from "./entities/blog/blog.entity";

AdminBro.registerAdapter({ Database, Resource });

async function bootstrap() {
  const connection = await createConnection({
    type: "postgres",
    host: "localhost",
    port: 5432,
    username: "postgres",
    password: "1",
    entities: [__dirname + "/**/*.entity{.js}"],
    database: "postgres",
    synchronize: true,
    migrationsRun: true,
    migrationsTransactionMode: "all",
    logging: true,
  });

  // // // Applying connection to model
  Blog.useConnection(connection);
  // // Person.useConnection(connection);

  const adminBro = new AdminBro({
    locale: {
      language: "ru",
      translations: {},
    },
    branding: {
      companyName: "Elenafurs",
      softwareBrothers: false,
      logo: "https://elenafurs.ru/public/app/img/logo-mini.svg",
    },
    // databases: [connection],
    resources: [{ resource: Blog, options: { parent: { name: "foobar" } } }],
    rootPath: "/admin",
  });

  const app = express();

  console.log(app);
  const router = AdminBroExpress.buildRouter(adminBro);
  app.use(adminBro.options.rootPath, router);
  await app.listen(3000);
}
bootstrap();

query: START TRANSACTION
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = current_schema() AND "table_name" = 'typeorm_metadata'
query: COMMIT
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = current_schema() AND "table_name" = 'migrations'
query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC
(node:70454) UnhandledPromiseRejectionWarning: NoResourceAdapterError: There are no adapters supporting one of the resource you provided
at /Users/jamshedlatipov/work/elenafurs-express-admin/node_modules/admin-bro/lib/backend/utils/resources-factory.js:93:15
at Array.map ()
at ResourcesFactory._convertResources (/Users/jamshedlatipov/work/elenafurs-express-admin/node_modules/admin-bro/lib/backend/utils/resources-factory.js:87:22)
at ResourcesFactory.buildResources (/Users/jamshedlatipov/work/elenafurs-express-admin/node_modules/admin-bro/lib/backend/utils/resources-factory.js:42:35)
at new AdminBro (/Users/jamshedlatipov/work/elenafurs-express-admin/node_modules/admin-bro/lib/admin-bro.js:168:39)
at /Users/jamshedlatipov/work/elenafurs-express-admin/app.js:71:32
at step (/Users/jamshedlatipov/work/elenafurs-express-admin/app.js:33:23)
at Object.next (/Users/jamshedlatipov/work/elenafurs-express-admin/app.js:14:53)
at fulfilled (/Users/jamshedlatipov/work/elenafurs-express-admin/app.js:5:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use node --trace-warnings ... to show where the warning was created)
(node:70454) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:70454) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@iamraffe
Copy link

iamraffe commented Sep 4, 2020

The same thing is happening to me. Were you able to solve this error?

@Protectator
Copy link

Getting the same error in my project. Here is the relevant part of my dependencies :

    "@admin-bro/express": "^3.0.0",
    "@admin-bro/typeorm": "^1.2.0",
    "admin-bro": "^3.1.2",
    "express": "^4.17.1",
    "pg": "^8.2.1",
    "reflect-metadata": "^0.1.13",
    "typeorm": "^0.2.25",

And I'm using Node 14.4.0.

@giuseppecutuli
Copy link

giuseppecutuli commented Sep 9, 2020

Hello @Protectator @iamraffe @JamshedLatipov, try to extends the Entity with BaseEntity from typeorm. Work form me.

import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm';
@entity()
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;

@column()
firstName: string;

@column()
lastName: string;

@column({ default: true })
isActive: boolean;
}`

@Protectator
Copy link

My Entity is already extending the BaseEntity class, it doesn't work.

@wojtek-krysiak
Copy link
Contributor

i think that you have different versions of AdminBro installed in the app. Try to run npm ls admin-bro.

if that is the case make sure to have the latest one in you package.json. Remove none_modules and install everything again.

Let me know if that helped.

@ahayder
Copy link

ahayder commented Oct 20, 2020

any luck anyone?

@iamraffe
Copy link

I'm 99.9% I fixed it by extending my entities from BaseEntity.

@CarlosFandango
Copy link

CarlosFandango commented Oct 22, 2020

+1
I'm having this issue as well. I've created a new project from the example and it's not working.

I dug a bit deeper and it appears that there is no metadata on the repository when the adapter is checked against it.

return !!rawResource.getRepository().metadata;

I'm quite lost. Anyone have any ideas why metadata wouldn't be generated on the repositories?

Simplified Readme.md example

import {
    BaseEntity,
    Entity, PrimaryGeneratedColumn, Column,
    createConnection,
} from "typeorm";
import express from "express";
import { Database, Resource, UseAsTitle, UseForSearch } from "admin-bro-typeorm";
import { validate } from 'class-validator'

import AdminBro from "admin-bro";
const AdminBroExpress = require("admin-bro-expressjs") // No types for admin-bro-expressjs so required instead
 
Resource.validate = validate;
AdminBro.registerAdapter({ Database, Resource });
 
@Entity({name: "Persons"})
export class Person extends BaseEntity
{
    @PrimaryGeneratedColumn()
    public id!: number;
    
    @Column({type: 'varchar'})
    public firstName!: string;
    
    @Column({type: 'varchar'})
    public lastName!: string;
    
    @UseAsTitle()
    public toString(): string
    {
        return `${this.firstName} ${this.lastName}`;
    }
}
 
( async () =>
{
    const connection = await createConnection({
        name: "default",
        type: "sqlite",
        database: "admin_bro_test",
        synchronize: true,
        logging: true,
        entities: [
            "src/entity/*.*"
        ],
        migrationsTableName: "typeorm_migrations",
        migrations: [
            "src/db/migration/*.{ts, js}"
        ],
    });
    
    // Applying connection to model
    Person.useConnection(connection);
    
    const adminBro = new AdminBro({
        // databases: [connection],
        resources: [
            { resource: Person, options: { parent: { name: "foobar" } } }
        ], 
        rootPath: '/admin',
    });
    
    const app = express();
    const router = AdminBroExpress.buildRouter(adminBro);
    app.use(adminBro.options.rootPath, router);
    app.listen(3000);
})();

Stacktrace

Including logging from connection

query: BEGIN TRANSACTION
query: SELECT * FROM "sqlite_master" WHERE "type" = 'table' AND "name" = 'typeorm_metadata'
query: COMMIT
(node:63057) UnhandledPromiseRejectionWarning: NoResourceAdapterError: There are no adapters supporting one of the resource you provided
    at /Users/carlstanley/Repos/Side-Projects/node_modules/admin-bro/lib/backend/utils/resources-factory.js:95:15
    at Array.map (<anonymous>)
    at ResourcesFactory._convertResources (/Users/carlstanley/Repos/Side-Projects/node_modules/admin-bro/lib/backend/utils/resources-factory.js:89:22)
    at ResourcesFactory.buildResources (/Users/carlstanley/Repos/Side-Projects/node_modules/admin-bro/lib/backend/utils/resources-factory.js:44:35)
    at new AdminBro (/Users/carlstanley/Repos/Side-Projects/node_modules/admin-bro/lib/admin-bro.js:166:39)

@CarlosFandango
Copy link

CarlosFandango commented Oct 22, 2020

UPDATE: I've found my problem!! This was a TypeORM problem.

in the connection, if referencing your entities using wildcards, it doesn't generate the entitiesmetadata which is asserted to determine if the adapter can work with the resource.

Not working (NoResourceAdapterError)

const connection = await createConnection({
        name: "default",
        type: "sqlite",
        database: "admin_bro_test",
        synchronize: true,
        logging: true,
        entities: [
            "src/entity/*.*"       //  <------- Wildcard entities used by TypeORM
        ],
        migrationsTableName: "typeorm_migrations",
        migrations: [
            "src/db/migration/*.{ts, js}"
        ],
    });

Working

AdminBro compiling.

const connection = await createConnection({
        name: "default",
        type: "sqlite",
        database: "admin_bro_test",
        synchronize: true,
        logging: true,
        entities: [
            Person       //  <---- Pass in the Entity here instead of using a wildcard
        ],
        migrationsTableName: "typeorm_migrations",
        migrations: [
            "src/db/migration/*.{ts, js}"
        ],
    });

Fix:

entities: [
            Person       //  <---- Pass in the Entity here instead of using a wildcard
        ],

@francofadini
Copy link

For anyone with this error, in my case was AdminBro initializing before my DB connection.

@pablosproject
Copy link

I had the same error, solved by using an Async Configuration and by extending BaseEntity in my entities

@talkl
Copy link

talkl commented Nov 29, 2020

For anyone with this error, in my case was AdminBro initializing before my DB connection.

this was my problem

@Darian-Certn
Copy link

Any updates on this issue for those of us that don't want to extend the BaseEntity class? This is a pretty silly thing to have to do if we are following the data mapper pattern and need an async config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests