opencode icon indicating copy to clipboard operation
opencode copied to clipboard

TypeError: undefined is not an object (evaluating 'mode.type')

Open a-essam23 opened this issue 1 year ago • 19 comments

Description

I saw a few old issues for this but all the solutions do not work. I'm using the default build mode. I've even deleted my opencode.json config file. It's important to note it's not broken everywhere. Only in some directories. My project directories (where I've used opencode before and consistently are broken) while using it in others is working fine. I'm unsure where the issue is.

I've tried using: 1- copilot 2- opencode zen (grok fast)

I've tried: 1- logging in again 2- rm -rf ~/.cache/opencode/ 3- npm update in ~.opencode and ~/.cache/opencode

Nothing works thus far.

OpenCode version

v1.0.107

Steps to reproduce

No response

Screenshot and/or share link

Image

Operating System

arch-linux

Terminal

kitty

a-essam23 avatar Nov 24 '25 11:11 a-essam23

This issue might be related to existing problems with undefined object access during initialization. While not exact duplicates, the following issues involve similar patterns and may provide useful context:

  • #4368: Similar error pattern with theme initialization - undefined is not an object (evaluating 'c3[mode2]') in theme context
  • #4425: TUI crash with undefined object access - undefined is not an object (evaluating 'sync.data.config.theme')
  • #4648: Another undefined object crash - undefined is not an object (evaluating 'color.buffer')
  • #4650: Flash crash on startup with incomplete initialization
  • #4646: Editor/TUI performance issues after upgrade (potentially related config state issues)

The pattern suggests this could be:

  1. A configuration initialization issue where expected properties are missing
  2. A mode/build configuration validation problem
  3. A cache state corruption similar to what others have reported

The fact that it's only broken in some directories (as mentioned in #4690) suggests it might be related to local configuration (.opencode/opencode.json or similar files) being incomplete or malformed in those specific directories.

Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Nov 24 '25 11:11 github-actions[bot]

hm ill take a look

rekram1-node avatar Nov 24 '25 13:11 rekram1-node

can u do:

opencode debug config

and show me output

rekram1-node avatar Nov 24 '25 13:11 rekram1-node

Running into the same issue even after deleting all of my commands and subagents and a fresh install

Output:

{
  "agent": {},
  "mode": {},
  "plugin": [],
  "command": {},
  "username": "so",
  "keybinds": {
    "leader": "ctrl+x",
    "app_exit": "ctrl+c,ctrl+d,<leader>q",
    "editor_open": "<leader>e",
    "theme_list": "<leader>t",
    "sidebar_toggle": "<leader>b",
    "status_view": "<leader>s",
    "session_export": "<leader>x",
    "session_new": "<leader>n",
    "session_list": "<leader>l",
    "session_timeline": "<leader>g",
    "session_share": "none",
    "session_unshare": "none",
    "session_interrupt": "escape",
    "session_compact": "<leader>c",
    "messages_page_up": "pageup",
    "messages_page_down": "pagedown",
    "messages_half_page_up": "ctrl+alt+u",
    "messages_half_page_down": "ctrl+alt+d",
    "messages_first": "ctrl+g,home",
    "messages_last": "ctrl+alt+g,end",
    "messages_copy": "<leader>y",
    "messages_undo": "<leader>u",
    "messages_redo": "<leader>r",
    "messages_toggle_conceal": "<leader>h",
    "model_list": "<leader>m",
    "model_cycle_recent": "f2",
    "model_cycle_recent_reverse": "shift+f2",
    "command_list": "ctrl+p",
    "agent_list": "<leader>a",
    "agent_cycle": "tab",
    "agent_cycle_reverse": "shift+tab",
    "input_clear": "ctrl+c",
    "input_forward_delete": "ctrl+d",
    "input_paste": "ctrl+v",
    "input_submit": "return",
    "input_newline": "shift+return,ctrl+j",
    "history_previous": "up",
    "history_next": "down",
    "session_child_cycle": "<leader>right",
    "session_child_cycle_reverse": "<leader>left",
    "terminal_suspend": "ctrl+z"
  }
}

coolehs avatar Nov 24 '25 13:11 coolehs

Here's the output for opencode debug config. Might be a little messy because I have a custom mode and command.

{
  "agent": {
    "design": {
      "prompt": "You are in **design mode**.\n\nYour purpose is to reason about systems, actions, and interactions — then propose improvements or alternative designs.\n\nFocus on:\n- Understanding **how things currently work** through actions, flows, and relationships\n- Representing these clearly using structured formats (lists, tables, sequences, diagrams)\n- Exploring **possible extensions, refactors, or simplifications**\n- Suggesting **patterns, architectures, or conceptual models** that could improve clarity or scalability\n\nGuidelines:\n- Do not execute or modify files — this is a reasoning and planning workspace\n- Stay analytical and concrete, but not afraid to propose creative directions\n- When proposing changes, explain their **rationale** and **trade-offs**\n- When context is unclear or multiple paths exist, **ask the user for clarification, confirmation, or direction** before proceeding\n- Encourage short, focused dialogues to align understanding before expanding ideas\n- Keep reasoning explicit, organized, and transparent\n\n\nEnd goal:\nDevelop both understanding and direction — a conceptual model of what exists, and a set of reasoned possibilities for what could exist, in collaboration with the user.",
      "tools": {
        "write": true,
        "edit": false,
        "bash": false,
        "read": true,
        "grep": true,
        "glob": true
      },
      "name": "design",
      "mode": "primary"
    }
  },
  "mode": {},
  "plugin": [],
  "command": {
    "investigate": {
      "template": "# Flow Investigation: $ARGUMENTS\n\nUsing the Universal Flow Investigation Template, conduct a comprehensive investigation of the **$ARGUMENTS** flow in this codebase.\n\n## Current Repository Structure\n!`find . -type f -name \"*.ts\" -o -name \"*.tsx\" -o -name \"*.js\" -o -name \"*.jsx\" | head -20`\n\n## Package Dependencies\n!`cat package.json | grep -A 20 \"dependencies\"`\n\n## Investigation Requirements\n\nStart with Phase 1 Discovery to locate all relevant files for the **$ARGUMENTS** flow, then systematically work through each phase. Fill in the template with actual values from the code, replacing all [PLACEHOLDER] markers.\n\n### Key Requirements:\n- Use unique IDs (EP_1, COMP_1, FN_1, etc.) and cross-reference them between sections\n- Mark checkboxes [x] as you complete discovery steps\n- Create ASCII diagrams for component relationships and data flows\n- Identify all database queries, API calls, and event handlers\n- Document security concerns and performance bottlenecks\n- Provide actionable recommendations with priority levels\n\n### Focus Areas:\n1. **Entry points** - How is the $ARGUMENTS flow triggered?\n2. **Data flow** - What transformations occur through the pipeline?\n3. **Dependencies** - What external services and internal components are used?\n4. **Error handling** - What edge cases exist and how are they handled?\n5. **Security & Performance** - Any vulnerabilities or bottlenecks?\n\n### Search Strategy for $ARGUMENTS:\nFirst, search for these patterns:\n- Core terms related to $ARGUMENTS\n- Routes containing $ARGUMENTS\n- Components with $ARGUMENTS in the name\n- Database models for $ARGUMENTS\n- API endpoints handling $ARGUMENTS\n\n## Output Format\nProvide the completed investigation using the template structure. For any unclear areas, note them in the Investigation Notes section with confidence levels.\n\nTarget completeness: >90% of template sections filled with actual code analysis.\n\n## Additional Context\n!`grep -r \"$ARGUMENTS\" --include=\"*.ts\" --include=\"*.tsx\" --include=\"*.js\" --include=\"*.jsx\" . | head -10`\n\nOutput the result in `/docs/$ARGUMENTS_FLOW_INVESTIGATION.md` in the project directory.\n---\n\n# Universal Flow Investigation Template v1.3-compact\n\n<!--LLM: Replace [PLACEHOLDER] with values. Use - [ ] unchecked, - [x] checked. Reference IDs: EP_n, COMP_n, FN_n, DB_n-->\n\n## Metadata\n**Flow:** [FLOW_NAME] | **Date:** [YYYY-MM-DD] | **Project:** [PROJECT_NAME]  \n**Stack:** [TECH_STACK] | **Scope:** [SCOPE] | **Status:** [IN_PROGRESS|COMPLETE]\n\n---\n\n## Quick Start\n### Critical Files <!--Priority: 🔴Critical 🟡High 🟢Standard-->\n| Priority | File | Purpose | Risk | Issues |\n|----------|------|---------|------|--------|\n| 🔴 | [path] | [description] | HIGH:[warning] | [gotchas] |\n\n### Pre-Change Checklist\n- [ ] Env vars: [LIST]\n- [ ] Services: [LIST]  \n- [ ] Tests: [LIST]\n- [ ] Notify: [LIST]\n\n### Key Functions\n| Function | Location | Purpose | Params | Safe? |\n|----------|----------|---------|--------|-------|\n| `[name()]` | [file:line] | [action] | `(p:type)` | [Y/N]-[why] |\n\n### Breaking Changes\n- Modifying [X] without [Y]\n- Changing [structure] in [location]\n- Removing [dependency]\n\n---\n\n## 1. Discovery & Entry Points\n\n### Search Terms\n- Core: `[term1, term2]`\n- Framework: `[term3, term4]`\n- Config: `[term5]`\n- Routes: `[/api/*, /path/*]`\n\n### File Locations <!--Check order-->\n```\n□ /config/* □ /auth/* □ /providers/*\n□ /middleware/* □ /api/* □ /services/*\n□ /utils/* □ .env* □ package.json\n```\n\n### Entry Points\n| ID | Name | Path | Type | Description |\n|----|------|------|------|-------------|\n| EP_1 | [name] | [path] | [Config\\|Route\\|Component] | [desc] |\n\n---\n\n## 2. Architecture\n\n### Core Components\n| ID | Component | Location | Type | Init | Dependencies |\n|----|-----------|----------|------|------|--------------|\n| COMP_1 | [name] | [path] | [Provider\\|Service] | [where:how] | [list] |\n\n### Component Relations\n```\n[App] COMP_1\n  └─wraps→ [AuthProvider] COMP_2\n            └─provides→ [useAuth] COMP_3\n```\n\n### Data Flow\n1. **Start:** [initial_state]\n2. **Trigger:** [event]\n3. **Process:** [step1] → [step2] → [stepN]\n4. **End:** [final_state]\n\n---\n\n## 3. Implementation\n\n### 3.1 Configuration\n**File:** [path]\n```javascript\n{\n  \"[key1]\": \"[value/type]\",\n  \"[key2]\": \"[value/type]\"\n}\n```\n\n### 3.2 Core Functions\n| ID | Name | Purpose | I/O | Side Effects |\n|----|------|---------|-----|--------------|\n| FN_1 | [name] | [action] | [in]→[out] | [effects] |\n\n### 3.3 State Management\n**Method:** [Context|Redux|Zustand]\n```typescript\n{\n  [key]: Type, // desc\n  [key2]: { [nested]: Type }\n}\n```\n\n### 3.4 External Services\n| ID | Service | Purpose | Config | Endpoints |\n|----|---------|---------|--------|-----------|\n| INT_1 | [name] | [why] | [file] | [GET /api/path] |\n\n### 3.5 Events/Communication\n\n#### Event System: [EventEmitter|WebSocket|SSE|Queue]\n| ID | Event | Emitter | Listeners | Payload | Purpose |\n|----|-------|---------|-----------|---------|---------|\n| EVT_1 | `[name]` | COMP_1 | COMP_2,3 | `{type,data}` | [why] |\n\n#### WebSocket\n- **URL:** `[wss://url]`\n- **Auth:** [method]\n- **Reconnect:** [strategy]\n\n#### Message Queue: [RabbitMQ|Redis|Kafka]\n| Queue | Publishers | Consumers | Purpose |\n|-------|------------|-----------|---------|\n| [name] | COMP_1 | COMP_2 | [why] |\n\n### 3.6 Database\n\n#### Config: [PostgreSQL|MySQL|MongoDB]\n- **Pool:** [min-max]\n- **ORM:** [Prisma|TypeORM|Sequelize]\n- **Connection:** [env_var]\n\n#### Models\n| ID | Model | Path | Relations |\n|----|-------|------|-----------|\n| MODEL_1 | User | [/models/User] | HasMany:Post |\n\n#### Queries\n| ID | Purpose | Location | Type | Index | Cache |\n|----|---------|----------|------|-------|-------|\n| Q_1 | [GetUserById] | [file:line] | Simple | [idx_user_id] | TTL:60s |\n\n#### Write Ops\n| ID | Operation | Transaction | Hooks | Validation |\n|----|-----------|-------------|-------|------------|\n| W_1 | CreateUser | YES | [beforeCreate] | [schema] |\n\n---\n\n## 4. Usage Patterns\n\n### Consumers\n| ID | Consumer | Path | Type | Purpose |\n|----|----------|------|------|---------|\n| USE_1 | [Component] | [path] | Hook | [why] |\n\n### Patterns\n**Pattern A:** [name]\n- Files: [list]\n- Example: `[code_snippet]`\n\n### Error Handling\n| ID | Scenario | Handler | Recovery |\n|----|----------|---------|----------|\n| ERR_1 | [condition] | [method] | [retry\\|fallback] |\n\n---\n\n## 5. Security & Performance\n\n### Security Checks\n- [ ] Auth at: [locations]\n- [ ] Input validation: [method] at [location]\n- [ ] Token type: [JWT|Session]\n- [ ] CORS: [origins]\n\n### Vulnerabilities\n| ID | Risk | Location | Severity | Fix |\n|----|------|----------|----------|-----|\n| VUL_1 | [type] | [file:line] | [HIGH\\|MED\\|LOW] | [action] |\n\n### Performance\n- **Bottlenecks:** [list]\n- **Cache:** [strategy]\n- **Bundle:** [size_kb]\n\n---\n\n## 6. Summary\n\n### Executive Overview\n[1-2 paragraphs: what it does, key architecture, critical dependencies]\n\n### Technical Flow\n```\nSTART → [Validate] → {Auth?} →NO→ [401]\n                        ↓YES\n                    [Process] → [Store] → [Cache] → END\n```\n\n### Key Files\n| Priority | File | Purpose | Risk |\n|----------|------|---------|------|\n| CRITICAL | [path] | [core_purpose] | HIGH |\n\n---\n\n## 7. Recommendations\n\n### Issues\n1. **ISSUE_1:** [problem] | Impact:[what] | Fix:[action] | Priority:[HIGH|MED|LOW]\n\n### Improvements\n1. **IMP_1:** [opportunity] | Current:[now] | Proposed:[future] | Benefit:[outcome]\n\n### Best Practices\n- [ ] Framework compliance: [Y/N/Partial]\n- [ ] Test coverage: [%]\n- [ ] Type safety: [Full/Partial/None]\n\n---\n\n## Appendix\n\n### A. Files\n1. `[path]` - [type:component|service] - [desc]\n\n### B. Dependencies\n```json\n{\"[package]\": \"[version]\"} // purpose\n```\n\n### C. Environment\n```bash\nVAR_NAME=\"value\" # purpose [REQUIRED|OPTIONAL]\n```\n\n### D. Related Flows\n- **[FlowName]:** [relationship] - [description]\n\n### E. Testing\n```bash\n# Unit: [command] - expect [N] pass\n# Integration: [setup] → [test] → [verify]\n```\n\n---\n\n## Notes\n**Observations:** [findings]  \n**Uncertain:** [needs_clarification]  \n**TODO:** [action_items]  \n**Confidence:** [HIGH|MED|LOW] | **Complete:** [%]\n\n---\n\n*Template v1.3-compact*\n\n<!--LLM_END: Verify all IDs unique, tables aligned, placeholders replaced-->",
      "description": "Investigate and document a code flow comprehensively",
      "agent": "build",
      "subtask": false
    }
  },
  "username": "ae",
  "keybinds": {
    "leader": "ctrl+x",
    "app_exit": "ctrl+c,ctrl+d,<leader>q",
    "editor_open": "<leader>e",
    "theme_list": "<leader>t",
    "sidebar_toggle": "<leader>b",
    "status_view": "<leader>s",
    "session_export": "<leader>x",
    "session_new": "<leader>n",
    "session_list": "<leader>l",
    "session_timeline": "<leader>g",
    "session_share": "none",
    "session_unshare": "none",
    "session_interrupt": "escape",
    "session_compact": "<leader>c",
    "messages_page_up": "pageup",
    "messages_page_down": "pagedown",
    "messages_half_page_up": "ctrl+alt+u",
    "messages_half_page_down": "ctrl+alt+d",
    "messages_first": "ctrl+g,home",
    "messages_last": "ctrl+alt+g,end",
    "messages_copy": "<leader>y",
    "messages_undo": "<leader>u",
    "messages_redo": "<leader>r",
    "messages_toggle_conceal": "<leader>h",
    "model_list": "<leader>m",
    "model_cycle_recent": "f2",
    "model_cycle_recent_reverse": "shift+f2",
    "command_list": "ctrl+p",
    "agent_list": "<leader>a",
    "agent_cycle": "tab",
    "agent_cycle_reverse": "shift+tab",
    "input_clear": "ctrl+c",
    "input_forward_delete": "ctrl+d",
    "input_paste": "ctrl+v",
    "input_submit": "return",
    "input_newline": "shift+return,ctrl+j",
    "history_previous": "up",
    "history_next": "down",
    "session_child_cycle": "<leader>right",
    "session_child_cycle_reverse": "<leader>left",
    "terminal_suspend": "ctrl+z"
  }
}

a-essam23 avatar Nov 24 '25 14:11 a-essam23

Downgrading to 1.0.105 fixed it, 1.0.106 has the same issue

relsunkaev avatar Nov 24 '25 19:11 relsunkaev

Hm taking a look

rekram1-node avatar Nov 24 '25 19:11 rekram1-node

I don't see mode.type in the codebase at all, and 1.0.105 works for everyone? Looking at the commits between dont see anything obvious yet

If anyone could run git bisect on the repo would be great ill keep looking tho

rekram1-node avatar Nov 24 '25 19:11 rekram1-node

so i tried uninstalling completely. same issue. i tested with curl and npm install.

git bisect returns nothing because there's no repo.

the issue occurs in certain directories not all. i have no clue why

a-essam23 avatar Nov 24 '25 19:11 a-essam23

downgrading to 1.0.105 works. though I'd appreciate a solution so I'm not locked into an old version

a-essam23 avatar Nov 24 '25 20:11 a-essam23

I meant like git bisecting in our source but that's a lot of effort for someone. Ill keep looking

rekram1-node avatar Nov 24 '25 20:11 rekram1-node

I don't think I fixed it but just to cross something off the list can someone try 1.0.109?

Also do yall have any custom themes that u were using, maybe transparent backgrounds? going to narrow it down more just wanna cross somethings off the list

rekram1-node avatar Nov 24 '25 22:11 rekram1-node

@rekram1-node that worked, thanks!

anthnykr avatar Nov 24 '25 22:11 anthnykr

oh lol how fun, perfect

rekram1-node avatar Nov 24 '25 22:11 rekram1-node

no custom themes here. give me 5 minutes I'll give it a test

a-essam23 avatar Nov 24 '25 22:11 a-essam23

Sounds good

rekram1-node avatar Nov 24 '25 23:11 rekram1-node

Yup. Looks like its working fine. Thank you for the quick response and updates. Really appreciate it. been working with opencode a lot lately and it was a pain to switch.

just out of curiosity, can you tell me what was the issue?

a-essam23 avatar Nov 24 '25 23:11 a-essam23

I honestly don't know exactly whaat was causing it, but we used to dynamically install npm deps to send requests to ur provider to reduce bundle size, now we bundle in openai, anthropic, and other providers automatically.

Whatever my logic was before was causing something to fail to resolve

rekram1-node avatar Nov 24 '25 23:11 rekram1-node

Here was the fix tho: https://github.com/sst/opencode/commit/9e44085a69a686d2632f6ae3d4d5f07bc75569c0

rekram1-node avatar Nov 24 '25 23:11 rekram1-node