Skip to content

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

Closed

Description

@jqbdyhz

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

Activity

  1. github-actions commented on Jan 5, 2026

    @github-actions
    Contributor

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

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

  2. jqbdyhz commented on Jan 5, 2026

    @jqbdyhz
    Author

    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.

  3. jqbdyhz commented on Jan 5, 2026

    @jqbdyhz
    Author

    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

  4. changed the title [-]Windows: auth login fails with 'Cannot find module @openauthjs/openauth/pkce'[/-] [+]Windows: OpenCode fails to start - Cannot find module '@openauthjs/openauth/pkce'[/+] on Jan 5, 2026
  5. ni-caicai commented on Jan 12, 2026

    @ni-caicai

    $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

  6. HWOUq1xd7c commented on Feb 19, 2026

    @HWOUq1xd7c

    用everything去清理掉所有和openauth有关的内容,并清空全局npm-cache,卸载opencode并重装,经测试有效

  7. github-actions commented on Apr 21, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions