Files
Deep-Package-Inspection/docs/log/2026-07-23-0911-final-agent-import-fix.md
T

1.5 KiB

Final Fix: Cleaned Up Server Actions Loader ReferenceError: Agent is not defined

Trigger: Dev server crash on page reload (ReferenceError: Agent is not defined) Date: 2026-07-23 09:11 WIB Affected files:

  • src/lib/actions/agents.ts
  • src/lib/actions/agentsCore.ts
  • 6 consumer components importing Agent type.

Root Cause

Next.js Server Actions compiler processes any file containing "use server" at the top, and registers all of its exported identifiers as API action fetchers. When it sees export { Agent }, it tries to register Agent as a server action. Since Agent was a type interface in typescript, it did not exist as a real JavaScript value at runtime, leading to a ReferenceError: Agent is not defined or Invalid Server Action Value error.

Solution

  1. Removed the dummy Agent async function from src/lib/actions/agentsCore.ts entirely, reverting it to a clean TS type interface.
  2. Removed all exports and imports of the Agent type/value in src/lib/actions/agents.ts (the "use server" actions bundle). This leaves agents.ts containing only actual, valid server action functions (getAgents, getAgent, etc.).
  3. Redirected the Agent interface imports in all 6 customer files (components/views) to load directly from the non-server-action file @/lib/actions/agentsCore.
  4. This completely separates runtime value-based mutating actions from TypeScript-only type exports, solving the Next.js Action Loader build error.
  5. Checked that the project builds and runs cleanly with no errors.