HeadlinesBriefing favicon HeadlinesBriefing.com

AdminJS v7 ESM Fix for NestJS Developers

DEV Community •
×

AdminJS v7 switched to ESM modules, breaking compatibility with NestJS's CommonJS foundation. Developers face ERR_REQUIRE_ESM errors when trying to integrate the admin panel. The official example repository doesn't run due to a longstanding issue, leaving a gap for practical implementation.

The workaround involves using dynamic `import()` inside an async function, isolating ESM loading. This keeps the rest of the project in CommonJS, avoiding package.json or tsconfig changes. The solution requires a dedicated loader file and async setup in the main application module, paying the async cost only once at startup.

This approach lets teams adopt AdminJS v7 without rewriting their entire codebase or forcing ESM on the team. While not the most elegant solution, it's contained and practical. Developers should avoid top-level ESM imports and keep all AdminJS-related code inside the async loader to prevent runtime crashes.