Skip to content

Wrapper script trying to execute native binary with Node.js if installed by pnpm #7911

@chuckchen

Description

@chuckchen

Description

The postinstall.mjs script creates a symlink from bin/opencode to the native binary on non-Windows platforms. However, the bin/opencode file is a Node.js wrapper script that's designed to locate and execute the platform-specific binary.

When the postinstall script replaces this wrapper with a symlink to the native binary, the system tries to execute the binary using the Node.js shebang (#!/usr/bin/env node), which fails because the binary is a native executable, not a Node.js script.

Plugins

No response

OpenCode version

No response

Steps to reproduce

  1. Install with pnpm:
    $ pnpm add -g opencode-ai
     WARN  4 deprecated subdependencies found: @koa/[email protected], [email protected], [email protected], [email protected]
    Packages: +2
    ++
    Progress: resolved 679, reused 651, downloaded 0, added 0, done
  2. Start wrapper script opencode before running postinstall script:
    $ opencode --version
    1.13.1
  3. Run the postinstall script from opencode-ai:
    $ pnpm approve-builds -g
    ✔ Choose which packages to build (Press <space> to select, <a> to toggle all, <i> to invert selection) · opencode-ai
    ✔ The next packages will now be built: opencode-ai.
    Do you approve? (y/N) · true
    .pnpm/[email protected]/node_modules/opencode-ai: Running postinstall script, done in 37ms
  4. Start wrapper script again:
    $ opencode --version
    /Users/chuck/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/opencode-darwin-arm64/bin/opencode:1
    ����
    
    
    
    SyntaxError: Invalid or unexpected token
        at wrapSafe (node:internal/modules/cjs/loader:1638:18)
        at Module._compile (node:internal/modules/cjs/loader:1680:20)
        at Object..js (node:internal/modules/cjs/loader:1839:10)
        at Module.load (node:internal/modules/cjs/loader:1441:32)
        at Function._load (node:internal/modules/cjs/loader:1263:12)
        at TracingChannel.traceSync (node:diagnostics_channel:328:14)
        at wrapModuleLoad (node:internal/modules/cjs/loader:237:24)
        at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
        at node:internal/main/run_main_module:36:49
    
    Node.js v22.21.1

Screenshot and/or share link

No response

Operating System

macOS 26.3

Terminal

Ghostty

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions