fix(build): compatibilidade CommonJS para Kernel

- Adiciona fallback para import.meta.url em builds do Docker
- Protege entry point do Kernel para não crashar em CommonJS
- DashboardServer.ts agora funciona em ESM e CommonJS
- index.ts com try-catch em torno de import.meta.url

Isso corrige o erro: ERR_INVALID_ARG_TYPE no build do Coolify

Refs: Deploy produção com Kernel
This commit is contained in:
Jonas Pacheco 2026-04-02 18:00:10 -03:00
parent 75953a8542
commit 5ba2bd963d
2 changed files with 32 additions and 13 deletions

View File

@ -105,8 +105,15 @@ export class DashboardServer {
this.app.use('/api/kernel', kernelRoutes); this.app.use('/api/kernel', kernelRoutes);
// Serve dashboard HTML // Serve dashboard HTML
const __filename = fileURLToPath(import.meta.url); // Suporte a ESM e CommonJS (build do Docker)
const __dirname = dirname(__filename); const __dirname = (() => {
try {
return dirname(fileURLToPath(import.meta.url));
} catch {
// Fallback para CommonJS build
return join(process.cwd(), 'server', 'kernel', 'dashboard');
}
})();
const publicPath = join(__dirname, 'public'); const publicPath = join(__dirname, 'public');
this.app.get('/', (req: Request, res: Response) => { this.app.get('/', (req: Request, res: Response) => {

View File

@ -12,8 +12,15 @@ import { LogAggregator } from './core/LogAggregator';
import { DashboardServer } from './dashboard/DashboardServer'; import { DashboardServer } from './dashboard/DashboardServer';
import { ServiceConfig, ServiceState } from './types'; import { ServiceConfig, ServiceState } from './types';
const __filename = fileURLToPath(import.meta.url); // Suporte a ESM e CommonJS (build do Docker)
const __dirname = dirname(__filename); const __dirname = (() => {
try {
return dirname(fileURLToPath(import.meta.url));
} catch {
// Fallback para CommonJS build
return join(process.cwd(), 'server', 'kernel');
}
})();
export interface KernelOptions { export interface KernelOptions {
configPath?: string; configPath?: string;
@ -200,7 +207,9 @@ export { createKernelRoutes } from './api/routes';
export * from './types'; export * from './types';
// Entry point para execução direta // Entry point para execução direta
if (import.meta.url === `file://${process.argv[1]}`) { // Protegido para funcionar no build CommonJS do Docker
try {
if (import.meta.url && import.meta.url === `file://${process.argv[1]}`) {
const kernel = new ArcadiaKernel({ const kernel = new ArcadiaKernel({
dashboard: { enabled: true, port: 5001 }, dashboard: { enabled: true, port: 5001 },
autoStart: true, autoStart: true,
@ -210,4 +219,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
console.error('[Kernel] Falha ao iniciar:', error); console.error('[Kernel] Falha ao iniciar:', error);
process.exit(1); process.exit(1);
}); });
}
} catch {
// No build CommonJS, o Kernel é iniciado pelo server/index.ts
} }