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

Closed
opened 2026-02-16 17:45:29 -05:00 by yindo · 1 comment
Owner

Originally created by @chuckchen on GitHub (Jan 11, 2026).

Originally assigned to: @thdxr on GitHub.

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/router@14.0.0, keygrip@1.1.0, node-domexception@1.0.0, whatwg-encoding@3.1.1
    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/opencode-ai@1.1.13/node_modules/opencode-ai: Running postinstall script, done in 37ms
    
  4. Start wrapper script again:
    $ opencode --version
    /Users/chuck/Library/pnpm/global/5/.pnpm/opencode-darwin-arm64@1.1.13/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

Originally created by @chuckchen on GitHub (Jan 11, 2026). Originally assigned to: @thdxr on GitHub. ### 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: ```sh $ pnpm add -g opencode-ai  WARN  4 deprecated subdependencies found: @koa/router@14.0.0, keygrip@1.1.0, node-domexception@1.0.0, whatwg-encoding@3.1.1 Packages: +2 ++ Progress: resolved 679, reused 651, downloaded 0, added 0, done ``` 3. Start wrapper script `opencode` before running postinstall script: ```sh $ opencode --version 1.13.1 ``` 4. Run the postinstall script from opencode-ai: ```sh $ 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/opencode-ai@1.1.13/node_modules/opencode-ai: Running postinstall script, done in 37ms ``` 6. Start wrapper script again: ```sh $ opencode --version /Users/chuck/Library/pnpm/global/5/.pnpm/opencode-darwin-arm64@1.1.13/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
yindo added the bug label 2026-02-16 17:45:29 -05:00
yindo closed this issue 2026-02-16 17:45:29 -05:00
Author
Owner

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

I've searched through existing issues and did not find any clear duplicates of this specific postinstall symlink problem. This appears to be a unique issue related to how the postinstall script handles the wrapper script on non-Windows platforms when installed via pnpm.

The issue is well-documented with clear reproduction steps and error messages, which should help in diagnosing and fixing the underlying problem.

@github-actions[bot] commented on GitHub (Jan 11, 2026): I've searched through existing issues and did not find any clear duplicates of this specific postinstall symlink problem. This appears to be a unique issue related to how the postinstall script handles the wrapper script on non-Windows platforms when installed via pnpm. The issue is well-documented with clear reproduction steps and error messages, which should help in diagnosing and fixing the underlying problem.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4801