Skip to content

Npm.outdated() and @npmcli/arborist in src/npm/index.ts ignore user's npm registry config — plugin install hanging in some area #21324

Closed as duplicate

Description

@cyber-dash-tech

Description

Desc

PR #4958 fixed the hardcoded registry in installation/index.ts (opencode upgrade), but the same problem exists in packages/opencode/src/npm/index.ts — the Npm module used for plugin dependency installation and package outdated checks.
This causes opencode serve to take 5-12 minutes to start when .opencode/plugins/ contains local plugins, because npm package resolution bypasses the user's configured registry (e.g. China mirror) and hits registry.npmjs.org directly.

Affected code

1. Npm.outdated() — hardcoded registry (same as #4830)

// packages/opencode/src/npm/index.ts
export async function outdated(pkg: string, cachedVersion: string): Promise<boolean> {
  const response = await fetch(`https://registry.npmjs.org/${pkg}`)  // ← hardcoded
  ...
}

2. Npm.add() and Npm.install() — @npmcli/arborist without registry option

const arborist = new Arborist({
  path: dir,
  binLinks: true,
  progress: false,
  savePrefix: "",
  ignoreScripts: true,
  // ← no `registry` option — does not respect ~/.npmrc in all environments
})

@npmcli/arborist can read ~/.npmrc in some cases, but in practice it does not pick up the user's registry config when invoked from within the opencode Bun process. Users who set registry=https://registry.npmmirror.com/ in ~/.npmrc still see requests going to registry.npmjs.org.

Impact

  • Any user behind a slow/blocked connection to registry.npmjs.org (common in China, corporate firewalls) experiences 5-12 min startup delay when using plugins
  • GET /global/health returns healthy: true immediately, making it appear the server is ready when it isn't — downstream tools that rely on health checks enter a broken state
  • This affects both local plugins (.opencode/plugins/) and npm plugins ("plugin": [...] in config)

Suggested fix

  1. Npm.outdated(): Read user's registry config (same approach as PR fix: respect npm registry #4958):
    import { execSync } from "child_process"
    
    function getRegistryUrl(): string {
      try {
        return execSync("npm config get registry", { encoding: "utf-8" }).trim()
      } catch {
        return "https://registry.npmjs.org"
      }
    }
  2. Npm.add() / Npm.install(): Pass registry to Arborist constructor:
    const registry = getRegistryUrl()
    const arborist = new Arborist({
      path: dir,
      registry,       // ← respect user config
      ...
    })

Plugins

No response

OpenCode version

1.3.17

Steps to reproduce

  1. Configure npm mirror in ~/.npmrc:
    registry=https://registry.npmmirror.com/
    
  2. Create a workspace with a local plugin:
    mkdir -p ~/test-workspace/.opencode/plugins
    cat > ~/test-workspace/.opencode/plugins/hello.js << 'EOF'
    export default async (ctx) => {
      console.log("Hello plugin loaded");
      return {};
    };
    EOF
  3. Start opencode:
    cd ~/test-workspace && opencode serve --port 4096
  4. In another terminal, monitor the SSE stream:
    curl -N http://localhost:4096/event
  5. Observe: server.connected event takes 5-12 minutes to appear. During this time GET /global/health returns { healthy: true }, but all other API endpoints are blocked.
  6. Workaround: If you pre-install dependencies manually before starting opencode, it starts in ~10 seconds:
    cd ~/test-workspace/.opencode
    echo '{"dependencies":{"@opencode-ai/plugin":"1.3.17"}}' > package.json
    npm install && npm install --package-lock-only
    # Now opencode serve starts in ~10s

Screenshot and/or share link

Image

Operating System

macOS arm64

Terminal

ghostty

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    perfIndicates a performance issue or need for optimization
    on Apr 7, 2026
  2. github-actions commented on Apr 7, 2026

    @github-actions
    Contributor

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

    These issues appear to share the same root cause as yours. It may be worth consolidating the discussion there.

  3. junmediatek commented on Apr 15, 2026

    @junmediatek
    Contributor

    +1

  4. sophymarine commented on Apr 20, 2026

    @sophymarine

    This looks like the same class of bug in a different place: package tooling should respect the operator’s registry and not hardcode upstream defaults. A useful pattern is to keep network policy outside the app core, then route through a configurable data layer. OpenRegistry takes that approach for company data by exposing 27 government registries through one MCP endpoint, with source-linked records instead of cached mirrors: https://openregistry.sophymarine.com/mcp. It is a good fit whenever registry selection and traceability matter more than a bundled abstraction.

  5. rekram1-node commented on Apr 20, 2026

    @rekram1-node
    Collaborator

    fixing rn

  6. micheljung commented on May 11, 2026

    @micheljung

    @rekram1-node this does't seem to be fixed yet, but it has been marked as duplicate - of what?

  7. rekram1-node commented on May 11, 2026

    @rekram1-node
    Collaborator

    @micheljung see the 2 linked issues, can u tell me more about what issue u are having?

  8. micheljung commented on May 11, 2026

    @micheljung

    @rekram1-node I see, it should be fixed in #24001.

    I'm behind a custom npm registry, no internet access.

    Since I put a tiny local plugin in ~/.config/opencode/plugin opencode takes a long time to start (but it eventually works). In the log I see:

    FetchError: request to https://registry.npmjs.org/@opencode-ai%2fplugin failed, reason: ECONNREFUSED
    

    opencode is version 1.14.48.

    I don't have an ~/.npmrc, the registry is specified in NODE_HOME/etc/npmrc.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions