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

ERROR: Trying to bundle file but it doesn't exist #1330

Open olucasandrade opened 1 year ago

olucasandrade commented 1 year ago

I have an api with adminjs and upload feature with aws s3 that is working correctly when i run locally. But when deployed on vercel i get the following error:

t.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
Legacy server listening...
2022-12-08T12:33:06.859Z    undefined   ERROR   Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"ConfigurationError: \n    Trying to bundle file '/var/task/node_modules/@adminjs/upload/src/features/upload-file/components/edit' but it doesn't exist\n    More information can be found at: https://docs.adminjs.co/AdminJS.html\n    ","reason":{"errorType":"ConfigurationError","errorMessage":"\n    Trying to bundle file '/var/task/node_modules/@adminjs/upload/src/features/upload-file/components/edit' but it doesn't exist\n    More information can be found at: https://docs.adminjs.co/AdminJS.html\n    ","name":"ConfigurationError","stack":["ConfigurationError: ","    Trying to bundle file '/var/task/node_modules/@adminjs/upload/src/features/upload-file/components/edit' but it doesn't exist","    More information can be found at: https://docs.adminjs.co/AdminJS.html","    ","    at Function.resolveFilePath (/var/task/node_modules/adminjs/lib/backend/utils/component-loader.js:108:11)","    at ComponentLoader.__unsafe_addWithoutChecks (/var/task/node_modules/adminjs/lib/backend/utils/component-loader.js:52:46)","    at Function.bundle (/var/task/node_modules/adminjs/lib/adminjs.js:391:41)","    at uploadFileFeature (/var/task/node_modules/@adminjs/upload/build/features/upload-file/upload-file.feature.js:75:45)","    at AdminOptions.buildResources (/var/task/src/utils/buildAdminOptions.js:235:21)","    at module.exports (/var/task/src/main/config/setup.js:18:39)","    at Object.<anonymous> (/var/task/src/main/config/app.js:6:1)","    at Module._compile (internal/modules/cjs/loader.js:1085:14)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)","    at Module.load (internal/modules/cjs/loader.js:950:32)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: ConfigurationError: ","    Trying to bundle file '/var/task/node_modules/@adminjs/upload/src/features/upload-file/components/edit' but it doesn't exist","    More information can be found at: https://docs.adminjs.co/AdminJS.html","    ","    at process.<anonymous> (/var/runtime/index.js:35:15)","    at process.emit (events.js:412:35)","    at process.emit (domain.js:475:12)","    at processPromiseRejections (internal/process/promises.js:245:33)","    at processTicksAndRejections (internal/process/task_queues.js:96:32)"]}
2022-12-08T12:33:06.863Z    undefined   ERROR   Unhandled rejection: ConfigurationError: 
    Trying to bundle file '/var/task/node_modules/@adminjs/upload/src/features/upload-file/components/edit' but it doesn't exist
    More information can be found at: https://docs.adminjs.co/AdminJS.html
    at Function.resolveFilePath (/var/task/node_modules/adminjs/lib/backend/utils/component-loader.js:108:11)
    at ComponentLoader.__unsafe_addWithoutChecks (/var/task/node_modules/adminjs/lib/backend/utils/component-loader.js:52:46)
    at Function.bundle (/var/task/node_modules/adminjs/lib/adminjs.js:391:41)
    at uploadFileFeature (/var/task/node_modules/@adminjs/upload/build/features/upload-file/upload-file.feature.js:75:45)
    at AdminOptions.buildResources (/var/task/src/utils/buildAdminOptions.js:235:21)
    at module.exports (/var/task/src/main/config/setup.js:18:39)
    at Object.<anonymous> (/var/task/src/main/config/app.js:6:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
RequestId: c78d99be-b47c-4848-942d-37a81c45fe78 Error: Runtime exited with error: exit status 1
Runtime.ExitError

Installed libraries and their versions

"@adminjs/bundler": "^2.0.0",
"@adminjs/express": "^5.0.1",
"@adminjs/mongoose": "^3.0.0",
"@adminjs/upload": "^3.0.1",
"adminjs": "^6.6.5",

Setup

    require('dotenv').config();
    app.use(express.static(path.join(__dirname, '../../../public/')));
    app.use('/uploads', express.static('uploads'));
    const adminOptions = {
        locale: adminOptions().buildLocales(),
        resources: adminOptions().buildResources(),
        branding: adminOptions().buildBranding(),
        assets: {
            styles: ['/styles.css'],
        },
    };
    AdminJS.registerAdapter({ Database, Resource });
    const admin = new AdminJS(adminOptions);
    const adminRouter = AdminJSExpress.buildAuthenticatedRouter(admin, {
        ...  
    });
    app.use(admin.options.rootPath, adminRouter);

my entry file generated automatically

import Component0 from '../node_modules/@adminjs/upload/src/features/upload-file/components/edit.tsx'
AdminJS.UserComponents.Component0 = Component0
import Component1 from '../node_modules/@adminjs/upload/src/features/upload-file/components/list.tsx'
AdminJS.UserComponents.Component1 = Component1
import Component2 from '../node_modules/@adminjs/upload/src/features/upload-file/components/show.tsx'
AdminJS.UserComponents.Component2 = Component2
import Component3 from '../node_modules/@adminjs/upload/src/features/upload-file/components/edit.tsx'
AdminJS.UserComponents.Component3 = Component3
import Component4 from '../node_modules/@adminjs/upload/src/features/upload-file/components/list.tsx'
AdminJS.UserComponents.Component4 = Component4
import Component5 from '../node_modules/@adminjs/upload/src/features/upload-file/components/show.tsx'
AdminJS.UserComponents.Component5 = Component5
import Component6 from '../node_modules/@adminjs/upload/src/features/upload-file/components/edit.tsx'
AdminJS.UserComponents.Component6 = Component6
import Component7 from '../node_modules/@adminjs/upload/src/features/upload-file/components/list.tsx'
AdminJS.UserComponents.Component7 = Component7
import Component8 from '../node_modules/@adminjs/upload/src/features/upload-file/components/show.tsx'
AdminJS.UserComponents.Component8 = Component8
import Component9 from '../node_modules/@adminjs/upload/src/features/upload-file/components/edit.tsx'
AdminJS.UserComponents.Component9 = Component9
import Component10 from '../node_modules/@adminjs/upload/src/features/upload-file/components/list.tsx'
AdminJS.UserComponents.Component10 = Component10
import Component11 from '../node_modules/@adminjs/upload/src/features/upload-file/components/show.tsx'
AdminJS.UserComponents.Component11 = Component11
import Component12 from '../node_modules/@adminjs/upload/src/features/upload-file/components/edit.tsx'
AdminJS.UserComponents.Component12 = Component12
import Component13 from '../node_modules/@adminjs/upload/src/features/upload-file/components/list.tsx'
AdminJS.UserComponents.Component13 = Component13
import Component14 from '../node_modules/@adminjs/upload/src/features/upload-file/components/show.tsx'
AdminJS.UserComponents.Component14 = Component14
import Component15 from '../node_modules/@adminjs/upload/src/features/upload-file/components/edit.tsx'
AdminJS.UserComponents.Component15 = Component15
import Component16 from '../node_modules/@adminjs/upload/src/features/upload-file/components/list.tsx'
AdminJS.UserComponents.Component16 = Component16
import Component17 from '../node_modules/@adminjs/upload/src/features/upload-file/components/show.tsx'
AdminJS.UserComponents.Component17 = Component17
import Component18 from '../node_modules/@adminjs/upload/src/features/upload-file/components/edit.tsx'
AdminJS.UserComponents.Component18 = Component18
import Component19 from '../node_modules/@adminjs/upload/src/features/upload-file/components/list.tsx'
AdminJS.UserComponents.Component19 = Component19
import Component20 from '../node_modules/@adminjs/upload/src/features/upload-file/components/show.tsx'
AdminJS.UserComponents.Component20 = Component20

Obs: I already tried to use @adminjs/bundler with ADMIN_JS_SKIP_BUNDLE="true", but i'm not sure if i'm doing it correctly.

And my project an only .js app.

dziraf commented 1 year ago

AdminJS needs node_modules in runtime.

ADMIN_JS_SKIP_BUNDLE="true" should skip runtime bundling if used with NODE_ENV=production, but AdminJS still needs access to node_modules to get app.bundle.js, design-system.bundle.js and global.bundle.js. Your entry file is theoretically correct but the error implies that the bundling started in the runtime though. It's best to check what's inside of generated components.bundle.js.

ReisoAphi commented 1 year ago

@dziraf, sir I didn't understand your answer, could you please be more specific?

ReisoAphi commented 1 year ago

Im getting file:///C:/Users/Hecto/OneDrive/Documentos/GitHub/test/node_modules/adminjs/lib/backend/utils/component-loader.js:80 throw new ConfigurationError(Trying to bundle file '${src}' but it doesn't exist, 'AdminJS.html');

This is how my componentLoader looks like

import { ComponentLoader } from "adminjs"; const componentLoader = new ComponentLoader(); const Components = { Dashboard: componentLoader.add("dashboard", "./dashboard"), };

export { Components, componentLoader };

ReisoAphi commented 1 year ago

I have been working on the problem, I'm working with TS. Now its kind of working but on the .entry.js its creating the files path with many //..//..//, is thast correct?

AdminJS.UserComponents = {} import dashboard from '../../../../../../../../C:/Users/Hecto/OneDrive/Documentos/GitHub/test/src/components/dashboard.jsx' AdminJS.UserComponents.dashboard = dashboard

Paroca72 commented 1 year ago

Here the same issue.. Someone know how to fix it?

I'm not using TS.. just JS

UPDATE: I'm on Windows. In my case I notice that in the component-loader.js on row 72 have: if (fs.existsSync(fileName)) {

This line always return false even when the path is correct. My solution was pass the absolute file path instead the relative.

import { ComponentLoader } from 'adminjs';
import path from 'path';

const componentLoader = new ComponentLoader();
let absolute = path.resolve('./app/components/my_input.jsx');

const Components = {
    MyInput: componentLoader.add('MyInput', absolute),
}

export { componentLoader, Components };
vinu commented 1 year ago

I had the same issue with v7 on Windows - no issue in *nix machines Solution https://github.com/SoftwareBrothers/adminjs/issues/1185#issuecomment-1676308332