SoftwareBrothers / adminjs

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

[Bug]: Cant get custom dashboard to display #1586

Closed mattrochon closed 10 months ago

mattrochon commented 10 months ago

What happened?

Followed the documentation to setup a custom dashboard:

image

MainDashboard.tsx

image

ComponentConfig.ts

image

Application.ts

Log output:

image

It all seems to be setup correctly but all i see if the default dashboard.

Bug prevalence

Always

AdminJS dependencies version

"dependencies": { "@adminjs/express": "^6.1.0", "@adminjs/prisma": "^5.0.1", "@adminjs/themes": "^1.0.1", "@types/express": "^4.17.21", "adminjs": "^7.4.2", "express": "^4.18.2", "express-formidable": "^1.2.0", "express-session": "^1.17.3", "nodemon": "^3.0.2", "prisma": "^5.6.0", "tslib": "^2.6.2" }, "devDependencies": { "tsx": "^4.6.2" },

What browsers do you see the problem on?

No response

Relevant log output

ComponentLoader {
  components: {
    Dashboard: {
      overrides: false,
      filePath: 'g:\\workspace\\REDACTED\\view\\MainDashboard''
    }
  }
}
{ Dashboard: 'Dashboard' }

Relevant code that's giving you issues

const adminOptions: AdminJSOptions = {
            componentLoader,
            resources: ResourceConfig.buildResourceList(prisma),
            rootPath: "/app",
            defaultTheme: dark.id,
            availableThemes: [dark, light, noSidebar],
            locale: ResourceConfig.buildNavList(),
            dashboard: {
                component: Components.Dashboard,
            },
        }

        const admin = new AdminJS(adminOptions);
dziraf commented 10 months ago
  1. Can you check if components.bundle.js appears in your browser's Network tab and if there're any contents?
  2. Can you check if the file actually exists at:'g:\\workspace\\REDACTED\\view\\MainDashboard'' (to make sure the resolved path is correct)? You can try to use path.join to provide an absolute path in case it works incorrectly with relative path.
mattrochon commented 10 months ago
  1. It exists and is loaded, but appears empty image
  2. The file definitely exists and its resolved by the path resolver image
dziraf commented 10 months ago

Try adding:

if (process.env.NODE_ENV === 'production') await admin.initialize();
else admin.watch();

after const admin = new AdminJS(adminOptions);

mattrochon commented 10 months ago

Solved it! Thanks so much