Skip to content

Bug: __dirname is not defined in ESM context (agentdb-cli.js) #82

@adambkovacs

Description

@adambkovacs

Description

When running agentdb CLI commands in a project with "type": "module" in package.json, the CLI fails with:

❌ __dirname is not defined

Root Cause

dist/agentdb/cli/agentdb-cli.js line 55 uses __dirname:

const schemaPath = path.join(__dirname, '../schemas/frontier-schema.sql');

But __dirname is a CommonJS global that doesn't exist in ESM modules.

Fix

Add ESM compatibility shim at the top of the file:

import { fileURLToPath } from 'url';
import { dirname } from 'path';

// ESM compatibility fix for __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Environment

  • Node.js: v22.x
  • agentic-flow: 1.10.2
  • OS: macOS
  • Project type: ESM ("type": "module" in package.json)

Workaround

Using pnpm patch to apply the fix locally until this is released.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions