From 5ba2bd963d1573b48beb054ff67e17ef6055ab6d Mon Sep 17 00:00:00 2001 From: Jonas Pacheco Date: Thu, 2 Apr 2026 18:00:10 -0300 Subject: [PATCH] fix(build): compatibilidade CommonJS para Kernel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- server/kernel/dashboard/DashboardServer.ts | 11 +++++-- server/kernel/index.ts | 34 +++++++++++++++------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/server/kernel/dashboard/DashboardServer.ts b/server/kernel/dashboard/DashboardServer.ts index 9e0d34b..e7e8c6b 100644 --- a/server/kernel/dashboard/DashboardServer.ts +++ b/server/kernel/dashboard/DashboardServer.ts @@ -105,8 +105,15 @@ export class DashboardServer { this.app.use('/api/kernel', kernelRoutes); // Serve dashboard HTML - const __filename = fileURLToPath(import.meta.url); - const __dirname = dirname(__filename); + // Suporte a ESM e CommonJS (build do Docker) + 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'); this.app.get('/', (req: Request, res: Response) => { diff --git a/server/kernel/index.ts b/server/kernel/index.ts index 56b6c95..186fc7b 100644 --- a/server/kernel/index.ts +++ b/server/kernel/index.ts @@ -12,8 +12,15 @@ import { LogAggregator } from './core/LogAggregator'; import { DashboardServer } from './dashboard/DashboardServer'; import { ServiceConfig, ServiceState } from './types'; -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); +// Suporte a ESM e CommonJS (build do Docker) +const __dirname = (() => { + try { + return dirname(fileURLToPath(import.meta.url)); + } catch { + // Fallback para CommonJS build + return join(process.cwd(), 'server', 'kernel'); + } +})(); export interface KernelOptions { configPath?: string; @@ -200,14 +207,19 @@ export { createKernelRoutes } from './api/routes'; export * from './types'; // Entry point para execução direta -if (import.meta.url === `file://${process.argv[1]}`) { - const kernel = new ArcadiaKernel({ - dashboard: { enabled: true, port: 5001 }, - autoStart: true, - }); +// Protegido para funcionar no build CommonJS do Docker +try { + if (import.meta.url && import.meta.url === `file://${process.argv[1]}`) { + const kernel = new ArcadiaKernel({ + dashboard: { enabled: true, port: 5001 }, + autoStart: true, + }); - kernel.start().catch((error) => { - console.error('[Kernel] Falha ao iniciar:', error); - process.exit(1); - }); + kernel.start().catch((error) => { + console.error('[Kernel] Falha ao iniciar:', error); + process.exit(1); + }); + } +} catch { + // No build CommonJS, o Kernel é iniciado pelo server/index.ts }