SoftwareBrothers / adminjs

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

Error: Component "xxx" has not been bundled, ensure it was added to your ComponentLoader instance (the one included in AdminJS options). #1378

Closed Inoir closed 5 months ago

Inoir commented 1 year ago

Describe the bug Ive added some custom components. All working fine on develop mode. As soon i build everything for production, the app cant find the components anymore. The components.bundle.js looks okay. components are in this file and also referenced on UserComponents on the adminjs object. Still doesnt render the components, instead show error from title, i should add components to componentloader.

Installed libraries and their versions

To Reproduce Cant, cause it works local. so i expect it also works on prod mode

Expected behavior Should render the components without error

Screenshots

Screenshot 2023-01-14 at 02 56 08

Screenshot 2023-01-14 at 02 56 52

Additional context There is a difference between the rendered dashboard custom component and the list-tag component output in the file. Dashboard ist wrapped with an function and exports default inside of this function. list tags just sets _default var and isnt wrapped in any function. Still dashboard isnt replaced also

luke37b commented 1 year ago

I'm having the exact same issue when deploying to prod.

components.bundle.js:1 Uncaught TypeError: (0 , r.default) is not a function
    at components.bundle.js:1:5170
    at components.bundle.js:1:6495
    at components.bundle.js:1:7384

react_devtools_backend.js:4012 Error: Component "Avatar" has not been bundled, ensure it was added to your ComponentLoader instance (the one included in AdminJS options).
    at f (app.bundle.js:9:156344)
    at El (global.bundle.js:21:62944)
    at Cs (global.bundle.js:21:119997)
    at wc (global.bundle.js:21:108959)
    at yc (global.bundle.js:21:108887)
    at gc (global.bundle.js:21:108749)
    at ic (global.bundle.js:21:105553)
    at ac (global.bundle.js:21:104103)
    at S (global.bundle.js:11:1374)
    at MessagePort.R (global.bundle.js:11:1906)
conoremclaughlin commented 1 year ago

1361 potentially related and may address these dev vs prod issues.

conoremclaughlin commented 1 year ago

It seems the issue is related to this line:

https://github.com/SoftwareBrothers/adminjs/blob/d4e59cba7ef772375af48b7d1e67b43e578eb386/src/frontend/components/property-type/base-property-component.tsx#L83

Where componentLoader isn't checked for the component existence, only the global UserComponents object, which is loaded from the adminjs/.entry.js file, and that file only gets written to in dev mode by admin.watch(). Makes sense to let us pass our components directly rather than file paths so any commonjs, es module, build environment, etc. complexity is abstracted away and left to the consumers of the library. Regardless, thanks for the hard work! This is a wonderful project.

Inoir commented 1 year ago

thanks for the hint @conoremclaughlin fixed it for now with just replacing the path in die .entry.js. since there is /src/ in there, we just replace in the pipeline with /dist/ and its working for now.