SoftwareBrothers / adminjs

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

Getting CurrentAdmin using hook results in error 500 #557

Closed hannyudayana closed 4 years ago

hannyudayana commented 4 years ago

Hi developer, thank you for pointing me into using the hook to get current admin. I have a functional component as follow:

import React, { useState, useEffect } from 'react';
import { Box, Label, Button } from 'admin-bro/components';
import { useCurrentAdmin } from 'admin-bro';

const AdminNameLabel = props => {
    const [currentAdmin, setCurrentAdmin] = useCurrentAdmin();
    let content = (
        <React.Fragment>
            <Label>{currentAdmin.email}</Label>
        </React.Fragment>
    );
    return content;
}

The problem is, everytime I run the code, I got this error in the console:

GET http://localhost:8080/admin/frontend/assets/components.bundle.js net::ERR_ABORTED 500 (Internal Server Error)

Versions: "admin-bro": "^2.9.0", "admin-bro-expressjs": "^2.1.1", "admin-bro-sequelizejs": "^0.5.1",

Any help will be appreciated. Cheers

wojtek-krysiak commented 4 years ago

if you have 500 error from the backend - you should see something in the terminal where you launch your app. Are there any messages?

hannyudayana commented 4 years ago

There are no error message. These are the only messages shown on the terminal:

POST /admin/login 302 755.036 ms - 56
GET /admin 200 49.321 ms - 185018
GET /admin/frontend/assets/global.bundle.js 304 1.267 ms - -
GET /admin/frontend/assets/app.bundle.js 304 3.597 ms - -
GET /admin/frontend/assets/components.bundle.js 500 6612.001 ms - 2895
GET /admin/frontend/assets/logo-mini.svg 304 1028.448 ms - -
[BABEL] Note: The code generator has deoptimised the styling of D:\Project\node_modules\@ckeditor\ckeditor5-build-classic\build\ckeditor.js as it exceeds the max of 500KB.
wojtek-krysiak commented 4 years ago

ok - can you

  1. try to install admin-bro@3.0.1 (latest) this should fix the error with ckeditor
  2. if it wont fix error with ckeditor - remove this component and verify if the rest is working
hannyudayana commented 4 years ago

Installed the newest version 3.0.1.

  1. Now I am getting some error showing.

    'admin-bro/components' is imported by components\my-other-component.jsx, but could not be resolved – treating it as an external dependency
  2. ckeditor error is no more

I tried to change the import from 'admin-bro/components' to '@admin-bro/design-system', the error above is gone, but I still get this error:

GET /admin/frontend/assets/components.bundle.js 500 3062.879 ms - 2895

Versions: "admin-bro": "^3.0.1", "admin-bro-expressjs": "^2.1.1", "admin-bro-sequelizejs": "^0.5.1",

wojtek-krysiak commented 4 years ago

hm - probably you have some middleware which prevents errors from being seen. But there is another way of bundling files: with https://adminbro.com/AdminBro.html#watch method

so when you initialize your AdminBro instance like this: const admin = new AdminBro(options); immediately after that add admin.watch()

This will prevent /admin/frontend/assets/components.bundle.js from being generated on every request, but instead, admin will bundle them on every file change. Since probably you have some error in the components code Admin should throw this in the terminal.

hannyudayana commented 4 years ago

Ah finally. Admin.watch() shows me the error when building my functional component. I wonder why it doesn't show the error without .watch. Thank you so much for your help. I was driven crazy by the issue. Cheers