Running AdminJS v7 with NestJS: A Solution for North East Developers
In the ever-evolving world of software development, compatibility issues can often arise when using different libraries or frameworks. This article discusses a workaround for running AdminJS version 7 alongside NestJS, a popular framework in North East India and beyond.
The Challenge: ESM vs CommonJS
Recently, AdminJS, a popular open-source administration tool, moved to the ECMAScript Module (ESM) format in its latest version (v7). However, NestJS, another widely-used framework, still relies on CommonJS. This discrepancy led to a predicament for developers who wished to use both.
The Problem: Incompatible Requirements
When using the 'require' function to import AdminJS, developers faced an error due to the ESM-only nature of AdminJS v7. Attempting to use normal TypeScript imports and waiting for CommonJS to compile only led to more errors.
The Solution: Dynamic Import and Async Function
The solution lies in loading AdminJS and its dependencies using the 'dynamic import' function within an async function. By keeping the rest of the project in CommonJS format, developers can avoid the need for ESM throughout their project.
Relevance to North East India and Broader Indian Context
NestJS and AdminJS are popular frameworks among developers in North East India, as well as across the country. This workaround can help many developers who wish to use AdminJS v7 with NestJS, ensuring they can continue building their projects efficiently.
Implications and Future Outlook
While this solution is not the most elegant, it offers a practical, small, and contained workaround for developers who wish to use AdminJS v7 with NestJS without rewriting a significant portion of their codebase or forcing ESM on their entire team. As more libraries and frameworks transition to ESM, solutions like this may become increasingly important for developers.