adminjs-nestjs icon indicating copy to clipboard operation
adminjs-nestjs copied to clipboard

Latest AdminJS (6.1.0) does not work with Nest.js 11

Open ArtuGit opened this issue 10 months ago • 13 comments

After upgrading Nest.js to v11 /admin path return 404 error. It works with Nest.js 10.

ArtuGit avatar Apr 24 '25 12:04 ArtuGit

Hi, I also facing the same issue, I found out that it will need to await this.loader.register at onModuleInit in admin.module.ts, but I not familiar on how to contribute to the github code

mrsaki-law avatar Apr 29 '25 09:04 mrsaki-law

We are experiencing the same and couldn't find a solution for this yet

Uxio0 avatar May 08 '25 15:05 Uxio0

I am also facing the same issue after upgrade to Nestjs v11

saputradharma avatar May 21 '25 02:05 saputradharma

Not worth considering if you are on Nest 11.

jadewale avatar Jul 16 '25 14:07 jadewale

Any updates?

UPD

Those who struggling

diff --git a/node_modules/@adminjs/nestjs/build/admin.module.js b/node_modules/@adminjs/nestjs/build/admin.module.js
index e99b4f9..86ad837 100644
--- a/node_modules/@adminjs/nestjs/build/admin.module.js
+++ b/node_modules/@adminjs/nestjs/build/admin.module.js
@@ -70,7 +70,7 @@ let AdminModule = AdminModule_1 = class AdminModule {
         const admin = new AdminJS(adminJSOptions);
         admin.watch();
         const { httpAdapter } = this.httpAdapterHost;
-        this.loader.register(admin, httpAdapter, {
+        await this.loader.register(admin, httpAdapter, {
             ...this.adminModuleOptions,
             adminJsOptions: admin.options,
         });

Adding await in admin.moule.js file before this.loader.register helps

grokhotun avatar Jul 31 '25 21:07 grokhotun

I think more steps are required. I can access /admin but my server can't find the assets (I added await before this.loader.register)

GET http://localhost:4010/admin/frontend/assets/global.bundle.js net::ERR_ABORTED 500 (Internal Server Error)Understand this error
GET http://localhost:4010/admin/frontend/assets/design-system.bundle.js net::ERR_ABORTED 500 (Internal Server Error)Understand this error
GET http://localhost:4010/admin/frontend/assets/app.bundle.js net::ERR_ABORTED 500 (Internal Server Error)

I really wanted to check whether routes of AdminJS are registered correctly, but there is no way to list all routes including sub routes in Express@5.

ZeroCho avatar Aug 01 '25 17:08 ZeroCho

Here's what I did to get this working for my own project because I need it quick. I made these changes a while ago, so I might be missing some details, but this is the general approach:

  1. added the await keyword as suggested in the previous comment.
  2. removed use of formidable.js because it conflicted with the body parser in NestJS 11.
  3. switched to the built-in NestJS parser by adding app.set('query parser', 'extended'); to main.ts.
  4. updated the code to use req.body instead of (req as any).fields to access parsed data from the express loader.

mrsaki-law avatar Aug 01 '25 20:08 mrsaki-law

I have a custom ExpressLoader in my app and used the same route reordering logic as in src/loaders/express.loader.ts. After upgrading to NestJS 11, all my custom AdminJS route handlers stopped working.

The issue was that code in ExpressLoader#reorderRoutes expects an undocumented _router field, but newer versions of Express only provide the router field. Once I replaced _router with router, everything started working again.

McMerph avatar Aug 12 '25 10:08 McMerph

I finally make it work thanks to @grokhotun and @McMerph comments. Also I have to put global.bundle.js, design-system.bundle.js app.bundle.js components.bundle.js to CDN instead of local file system, so that I can load them in any environment.

relavant issue1 relavant issue2

ZeroCho avatar Aug 13 '25 08:08 ZeroCho

Hi, i don't understand how you manage to fix the express issue ?

Caillouo avatar Aug 21 '25 09:08 Caillouo

Hi, i don't understand how you manage to fix the express issue ?

Go to a node_modules/@adminjs/nestjs/build/admin.module.js file in your node_modules folder, find this line

// some code before

this.loader.register(admin, httpAdapter, {
  ...this.adminModuleOptions,
  adminJsOptions: admin.options
});
// some code after

and add await right before it so it would be

// some code before
await this.loader.register(admin, httpAdapter, {
  ...this.adminModuleOptions,
  adminJsOptions: admin.options
});
// some code after

grokhotun avatar Aug 24 '25 11:08 grokhotun

I have a custom ExpressLoader in my app and used the same route reordering logic as in src/loaders/express.loader.ts. After upgrading to NestJS 11, all my custom AdminJS route handlers stopped working.

The issue was that code in ExpressLoader#reorderRoutes expects an undocumented _router field, but newer versions of Express only provide the router field. Once I replaced _router with router, everything started working again.

Thank you, this is what fixed it for me!

For those that want to patch it, edit build/loaders/express.loader.js and change any reference of _router to router.

I'm submitting a PR as well.

tomups avatar Sep 11 '25 22:09 tomups

Facing the same issue. any news regarding the PR?

benari-elpida avatar Sep 26 '25 07:09 benari-elpida