adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

Components.bundle.js returns 500 despite successful @adminjs/bundler execution

Open leonardomarchioro opened this issue 5 months ago โ€ข 1 comments

I'm using AdminJS with a custom componentLoader and custom components. I'm following the official bundling instructions, including @adminjs/bundler, to serve AdminJS in a Docker environment without write access to .adminjs.

However, when trying to access http://localhost:3000/admin/frontend/assets/components.bundle.js, the request fails with a 500 Internal Server Error, even though the bundling script completes successfully and the file exists.

What Iโ€™ve Done Added @adminjs/bundler

Created bundle-admin.ts:

import { bundle } from '@adminjs/bundler';
import { componentLoader } from "./components/index.js";

(async () => {
  await bundle({
    componentLoader,
    destinationDir: 'public',
  });
})();

Script runs correctly: yarn admin:bundle (also confirmed during Docker build phase)

Files such as components.bundle.js are generated inside public/

Added static middleware to app.ts:

this.app.use(express.static(path.join(process.cwd(), 'public'))); Confirmed that the file exists inside the Docker container

The Problem Even with the file present and being served via express.static, trying to load:

http://localhost:3000/admin/frontend/assets/components.bundle.js Results in:

500 Internal Server Error No visible logs are printed that would help pinpoint the failure.

๐Ÿงพ Project Details Directory structure inside Docker container:

/app
โ”œโ”€โ”€ dist
โ”‚   โ””โ”€โ”€ admin
โ”‚       โ”œโ”€โ”€ admin.js
โ”‚       โ”œโ”€โ”€ components
โ”‚       โ”œโ”€โ”€ bundle-admin.js
โ”œโ”€โ”€ public
โ”‚   โ”œโ”€โ”€ components.bundle.js โœ…
โ”œโ”€โ”€ node_modules
โ”œโ”€โ”€ prisma
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ yarn.lock

Dockerfile:

FROM node:18-alpine AS builder

WORKDIR /app

COPY package.json yarn.lock ./
COPY tsconfig.json ./
COPY prisma ./prisma
COPY src ./src

RUN yarn install --frozen-lockfile
RUN yarn prisma generate
RUN yarn build

FROM node:18-alpine AS runner

WORKDIR /app

COPY --from=builder /app/package.json ./
COPY --from=builder /app/yarn.lock ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma

ENV NODE_ENV=production

RUN yarn admin:bundle

EXPOSE 3000

CMD ["node", "dist/server.js"]

Versions

adminjs: ^7.8.16
@adminjs/express: ^6.1.1
@adminjs/prisma: ^5.0.4
@adminjs/bundler: ^3.0.0
@adminjs/themes: ^1.0.1
express: ^5.1.0
node: 18 (alpine)
typescript: ^5.8.3

Expected Behavior Bundled assets such as components.bundle.js should be served successfully from the /public directory via express.static.

Questions Is AdminJS expecting the bundle at a different path internally?

Is there an internal handler that's trying to resolve and serve components.bundle.js differently?

Do I need to register the static route before AdminJS middleware?

Any guidance or examples would be appreciated ๐Ÿ™

leonardomarchioro avatar Jul 30 '25 13:07 leonardomarchioro

If you place your assets in public dir and serve them via static middleware, you must also set assetsCDN in your AdminJS config: https://docs.adminjs.co/installation/migration-guide-v7#adminjs-bundler

Make sure that besides components.bundle.js you also move other bundle files into public directory.

dziraf avatar Jul 30 '25 14:07 dziraf