You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
opencode-rag mcp
file:///Users/philipp/Library/pnpm/store/v11/links/@/opencode-rag-plugin/1.22.2/59fcffce5014d05c70ae2afe386ed767e738675843fb1c93570a2dbc9c4189eb/node_modules/opencode-rag-plugin/dist/cli/commands/mcp.js:32
const logFilePath = require("node:path").resolve(process.cwd(), ".opencode", "opencode-rag.log");
^
ReferenceError: require is not defined
at Command.<anonymous> (file:///Users/philipp/Library/pnpm/store/v11/links/@/opencode-rag-plugin/1.22.2/59fcffce5014d05c70ae2afe386ed767e738675843fb1c93570a2dbc9c4189eb/node_modules/opencode-rag-plugin/dist/cli/commands/mcp.js:32:33)
at async Command.parseAsync (/Users/philipp/Library/pnpm/store/v11/links/@/commander/13.1.0/c0a713f680c3b987d29d3ea1d434d6b278163009f394559cb31386334cd9c358/node_modules/commander/lib/command.js:1104:5)
Node.js v24.15.0
AI comment:
ReferenceError: require is not defined
The project is configured as an ES module ("type": "module"), but mcp.js directly calls CommonJS require("node:path") instead of an ES import statement or createRequire().
Fix src/cli/commands/mcp.ts (or dist/.../mcp.js)
Problem: Hardcoded require("node:path") inside ESM module, plus relative log resolving without fallback check.
Fix: Replace require with standard ES module imports and fallback to standard user directories.
Good catch, @skorphil you (and your AI) nailed it!
Your diagnosis was spot on. The fix is in: mcp.ts was using the old CommonJS style (require) in a project that uses the modern ES module style, so it blew up with ReferenceError: require is not defined.
Funny thing is, it was really hard to notice, since I currently don't use the mcp actively:
opencode-rag mcp --help → worked fine
typecheck → passed
it only crashed when the MCP server actually failed to start, so the error you got was an error about the error 😅
Every other command (list, show, dump, query) already did it the right way - mcp was the odd one out.
About your suggested fallback (OPENCODE_DATA_DIR / user dirs): I left that part out for now, since every other command writes its log to the same spot (.opencode/opencode-rag.log in the current directory). Adding a fallback in just one place would make things inconsistent. But I'd happily take a PR that changes it everywhere at once - that's the right way to do it.
I'll ships in the next patch release (2.0.1) now.
Thanks again for the report!
Activity
skorphil commentedon Sep 17, 2026
AI comment:
ReferenceError: require is not defined
The project is configured as an ES module ("type": "module"), but mcp.js directly calls CommonJS require("node:path") instead of an ES import statement or createRequire().
Fix src/cli/commands/mcp.ts (or dist/.../mcp.js)
TypeScript
// Replace:
// const logFilePath = require("node:path").resolve(process.cwd(), ".opencode", "opencode-rag.log");
// With:
import path from "node:path";
import os from "node:os";
const baseDir = process.env.OPENCODE_DATA_DIR
|| path.resolve(process.cwd(), ".opencode");
const logFilePath = path.resolve(baseDir, "opencode-rag.log");
MrDoe commentedon Sep 22, 2026
Good catch, @skorphil you (and your AI) nailed it!
Your diagnosis was spot on. The fix is in: mcp.ts was using the old CommonJS style (require) in a project that uses the modern ES module style, so it blew up with ReferenceError: require is not defined.
Funny thing is, it was really hard to notice, since I currently don't use the mcp actively:
Every other command (list, show, dump, query) already did it the right way - mcp was the odd one out.
About your suggested fallback (OPENCODE_DATA_DIR / user dirs): I left that part out for now, since every other command writes its log to the same spot (.opencode/opencode-rag.log in the current directory). Adding a fallback in just one place would make things inconsistent. But I'd happily take a PR that changes it everywhere at once - that's the right way to do it.
I'll ships in the next patch release (2.0.1) now.
Thanks again for the report!