1.5 KiB
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.tssrc/lib/actions/agentsCore.ts- 6 consumer components importing
Agenttype.
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
- Removed the dummy
Agentasync function fromsrc/lib/actions/agentsCore.tsentirely, reverting it to a clean TS type interface. - Removed all exports and imports of the
Agenttype/value insrc/lib/actions/agents.ts(the "use server" actions bundle). This leavesagents.tscontaining only actual, valid server action functions (getAgents,getAgent, etc.). - Redirected the
Agentinterface imports in all 6 customer files (components/views) to load directly from the non-server-action file @/lib/actions/agentsCore. - This completely separates runtime value-based mutating actions from TypeScript-only type exports, solving the Next.js Action Loader build error.
- Checked that the project builds and runs cleanly with no errors.