Windows: OpenCode fails to start - Cannot find module '@openauthjs/openauth/pkce' #4229

Open
opened 2026-02-16 17:43:06 -05:00 by yindo · 4 comments
Owner

Originally created by @jqbdyhz on GitHub (Jan 5, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

When running opencode-cli.exe auth login on Windows, selecting "OpenCode Zen" provider causes an error:

error: Cannot find module '@openauthjs/openauth/pkce' from 'C:\Users\...\.cache\opencode\node_modules\opencode-anthropic-auth\index.mjs'

Root Cause

The @openauthjs/openauth package (version 0.4.3) has an incomplete npm release:

  • package.json declares exports: "./*": { "import": "./dist/esm/*.js" }
  • But the dist/esm/ directory does not exist in the published package
  • Only dist/types/ and src/ are present

When opencode-anthropic-auth tries to import from @openauthjs/openauth/pkce, module resolution fails.

Environment

  • OS: Windows 11 x64
  • OpenCode CLI version: 1.0.164 (from desktop installer at D:\OpenCode)
  • Also reproduced with pnpm-installed opencode-ai@1.1.2

Workaround

Manually create the missing file at:
~/.cache/opencode/node_modules/@openauthjs/openauth/dist/esm/pkce.js

With a self-contained PKCE implementation (base64url encode + SHA-256 challenge generation).

Suggested Fix

Either:

  1. Pin @openauthjs/openauth to a version that includes dist/esm/ in the published package
  2. Or update opencode-anthropic-auth to use a different import path that exists

🤖 Generated with Claude Code

Originally created by @jqbdyhz on GitHub (Jan 5, 2026). Originally assigned to: @rekram1-node on GitHub. ## Description When running `opencode-cli.exe auth login` on Windows, selecting "OpenCode Zen" provider causes an error: ``` error: Cannot find module '@openauthjs/openauth/pkce' from 'C:\Users\...\.cache\opencode\node_modules\opencode-anthropic-auth\index.mjs' ``` ## Root Cause The `@openauthjs/openauth` package (version 0.4.3) has an incomplete npm release: - `package.json` declares exports: `"./*": { "import": "./dist/esm/*.js" }` - But the `dist/esm/` directory **does not exist** in the published package - Only `dist/types/` and `src/` are present When `opencode-anthropic-auth` tries to import from `@openauthjs/openauth/pkce`, module resolution fails. ## Environment - OS: Windows 11 x64 - OpenCode CLI version: 1.0.164 (from desktop installer at `D:\OpenCode`) - Also reproduced with pnpm-installed `opencode-ai@1.1.2` ## Workaround Manually create the missing file at: `~/.cache/opencode/node_modules/@openauthjs/openauth/dist/esm/pkce.js` With a self-contained PKCE implementation (base64url encode + SHA-256 challenge generation). ## Suggested Fix Either: 1. Pin `@openauthjs/openauth` to a version that includes `dist/esm/` in the published package 2. Or update `opencode-anthropic-auth` to use a different import path that exists --- 🤖 Generated with [Claude Code](https://claude.com/claude-code)
yindo added the windows label 2026-02-16 17:43:06 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 5, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #5604: Installation fails on Fedora 43 with npm after version v1.0.152 - Similar missing module issues during installation
  • #4127: Cannot build OpenCode due to missing @tsconfig/bun dependency - Related module resolution issues
  • #4774: Docker container fails to start due to bun dependency install issue - Similar @openauthjs/openauth problems in containerized environments
  • #3936: Github Enterprise authorization - Related authentication module failures

Additionally, since this issue involves authentication keybinds and the auth login command, please check our pinned keybinds documentation: #4997

@github-actions[bot] commented on GitHub (Jan 5, 2026): This issue might be a duplicate of existing issues. Please check: - #5604: Installation fails on Fedora 43 with npm after version v1.0.152 - Similar missing module issues during installation - #4127: Cannot build OpenCode due to missing @tsconfig/bun dependency - Related module resolution issues - #4774: Docker container fails to start due to bun dependency install issue - Similar @openauthjs/openauth problems in containerized environments - #3936: Github Enterprise authorization - Related authentication module failures Additionally, since this issue involves authentication keybinds and the auth login command, please check our pinned keybinds documentation: #4997
Author
Owner

@jqbdyhz commented on GitHub (Jan 5, 2026):

Thanks for the auto-detection! I checked the related issues but this appears to be a distinct problem:

This is NOT a network/installation race condition - the package @openauthjs/openauth@0.4.3 is successfully downloaded, but its published npm tarball is missing the dist/esm/ directory entirely.

Evidence:

  • package.json declares: "./*": { "import": "./dist/esm/*.js" }
  • But only dist/types/ and src/ exist in the installed package
  • The src/pkce.ts source file exists, but no compiled dist/esm/pkce.js

This means the upstream package was published without running the build step, so the compiled ESM output is missing.

Workaround confirmed working: manually create ~/.cache/opencode/node_modules/@openauthjs/openauth/dist/esm/pkce.js with a self-contained PKCE implementation.

@jqbdyhz commented on GitHub (Jan 5, 2026): Thanks for the auto-detection! I checked the related issues but this appears to be a distinct problem: **This is NOT a network/installation race condition** - the package `@openauthjs/openauth@0.4.3` is successfully downloaded, but its published npm tarball is **missing the `dist/esm/` directory entirely**. Evidence: - `package.json` declares: `"./*": { "import": "./dist/esm/*.js" }` - But only `dist/types/` and `src/` exist in the installed package - The `src/pkce.ts` source file exists, but no compiled `dist/esm/pkce.js` This means the upstream package was published without running the build step, so the compiled ESM output is missing. Workaround confirmed working: manually create `~/.cache/opencode/node_modules/@openauthjs/openauth/dist/esm/pkce.js` with a self-contained PKCE implementation.
Author
Owner

@jqbdyhz commented on GitHub (Jan 5, 2026):

Update: Issue persists in v1.1.2 (Desktop App & CLI)

Just tested with a fresh install of v1.1.2 (both Desktop App and pnpm-installed CLI) - the issue still occurs.

Why the workaround keeps disappearing

After applying the workaround, OpenCode works fine. But the fix gets lost when:

  1. OpenCode auto-updates - dependencies are re-downloaded, overwriting the manually created pkce.js
  2. Cache rebuild - OpenCode sometimes rebuilds .cache/opencode/node_modules/
  3. System cleanup tools - tools like CCleaner may clean .cache directories

One-liner fix (PowerShell)

For anyone hitting this on Windows, here's a quick fix:

$d = "$env:USERPROFILE\.cache\opencode\node_modules\@openauthjs\openauth\dist\esm"; New-Item -ItemType Directory -Force -Path $d | Out-Null; @'
function base64UrlEncode(buffer) { const bytes = new Uint8Array(buffer); let binary = ""; for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]); return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); }
export async function generatePKCE() { const verifierBytes = new Uint8Array(32); crypto.getRandomValues(verifierBytes); const verifier = base64UrlEncode(verifierBytes); const encoder = new TextEncoder(); const data = encoder.encode(verifier); const hash = await crypto.subtle.digest("SHA-256", data); const challenge = base64UrlEncode(hash); return { verifier, challenge, method: "S256" }; }
export function createChallenge(verifier) { const encoder = new TextEncoder(); const data = encoder.encode(verifier); return crypto.subtle.digest("SHA-256", data).then(base64UrlEncode); }
'@ | Set-Content "$d\pkce.js" -Encoding UTF8; Write-Host "Fixed!"

Suggested permanent fix

The real fix should happen upstream - either:

  1. @openauthjs/openauth publishes a version with dist/esm/ included
  2. Or OpenCode pins to a working version / uses a different import path

🤖 Generated with Claude Code

@jqbdyhz commented on GitHub (Jan 5, 2026): ## Update: Issue persists in v1.1.2 (Desktop App & CLI) Just tested with a fresh install of v1.1.2 (both Desktop App and pnpm-installed CLI) - the issue still occurs. ### Why the workaround keeps disappearing After applying the workaround, OpenCode works fine. But the fix gets lost when: 1. **OpenCode auto-updates** - dependencies are re-downloaded, overwriting the manually created `pkce.js` 2. **Cache rebuild** - OpenCode sometimes rebuilds `.cache/opencode/node_modules/` 3. **System cleanup tools** - tools like CCleaner may clean `.cache` directories ### One-liner fix (PowerShell) For anyone hitting this on Windows, here's a quick fix: ```powershell $d = "$env:USERPROFILE\.cache\opencode\node_modules\@openauthjs\openauth\dist\esm"; New-Item -ItemType Directory -Force -Path $d | Out-Null; @' function base64UrlEncode(buffer) { const bytes = new Uint8Array(buffer); let binary = ""; for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]); return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); } export async function generatePKCE() { const verifierBytes = new Uint8Array(32); crypto.getRandomValues(verifierBytes); const verifier = base64UrlEncode(verifierBytes); const encoder = new TextEncoder(); const data = encoder.encode(verifier); const hash = await crypto.subtle.digest("SHA-256", data); const challenge = base64UrlEncode(hash); return { verifier, challenge, method: "S256" }; } export function createChallenge(verifier) { const encoder = new TextEncoder(); const data = encoder.encode(verifier); return crypto.subtle.digest("SHA-256", data).then(base64UrlEncode); } '@ | Set-Content "$d\pkce.js" -Encoding UTF8; Write-Host "Fixed!" ``` ### Suggested permanent fix The real fix should happen upstream - either: 1. `@openauthjs/openauth` publishes a version with `dist/esm/` included 2. Or OpenCode pins to a working version / uses a different import path --- 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@ni-caicai commented on GitHub (Jan 12, 2026):

$d = "$env:USERPROFILE.cache\opencode\node_modules@openauthjs\openauth\dist\esm"; New-Item -ItemType Directory -Force -Path $d | Out-Null; @'
function base64UrlEncode(buffer) { const bytes = new Uint8Array(buffer); let binary = ""; for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]); return btoa(binary).replace(/+/g, "-").replace(///g, "_").replace(/=+$/, ""); }
export async function generatePKCE() { const verifierBytes = new Uint8Array(32); crypto.getRandomValues(verifierBytes); const verifier = base64UrlEncode(verifierBytes); const encoder = new TextEncoder(); const data = encoder.encode(verifier); const hash = await crypto.subtle.digest("SHA-256", data); const challenge = base64UrlEncode(hash); return { verifier, challenge, method: "S256" }; }
export function createChallenge(verifier) { const encoder = new TextEncoder(); const data = encoder.encode(verifier); return crypto.subtle.digest("SHA-256", data).then(base64UrlEncode); }
'@ | Set-Content "$d\pkce.js" -Encoding UTF8; Write-Host "Fixed!"

Perfect repair,You are so great!

Suggested permanent fix

@ni-caicai commented on GitHub (Jan 12, 2026): $d = "$env:USERPROFILE\.cache\opencode\node_modules\@openauthjs\openauth\dist\esm"; New-Item -ItemType Directory -Force -Path $d | Out-Null; @' function base64UrlEncode(buffer) { const bytes = new Uint8Array(buffer); let binary = ""; for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]); return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); } export async function generatePKCE() { const verifierBytes = new Uint8Array(32); crypto.getRandomValues(verifierBytes); const verifier = base64UrlEncode(verifierBytes); const encoder = new TextEncoder(); const data = encoder.encode(verifier); const hash = await crypto.subtle.digest("SHA-256", data); const challenge = base64UrlEncode(hash); return { verifier, challenge, method: "S256" }; } export function createChallenge(verifier) { const encoder = new TextEncoder(); const data = encoder.encode(verifier); return crypto.subtle.digest("SHA-256", data).then(base64UrlEncode); } '@ | Set-Content "$d\pkce.js" -Encoding UTF8; Write-Host "Fixed!" Perfect repair,You are so great! Suggested permanent fix
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4229