Bug: __dirname is not defined in ESM context (agentdb-cli.js)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 812
- Forks
- 175
- Avg merge
- 2m
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with dist/agentdb/cli/agentdb-cli.js around line 55 and inspect how the CLI locates ../schemas/frontier-schema.sql. Run the agentdb CLI in a project whose package.json sets "type": "module", then verify the schema path resolves without the __dirname error and confirm normal CLI commands still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100