Skip to content

Bug Report: sharp module fails on macOS ARM64 (Apple Silicon) #94

@tenondecrpc

Description

@tenondecrpc

Environment

  • OS: macOS (Apple Silicon - ARM64)
  • Node.js version: v22.22.1 (via nvm)
  • Bun version: 1.3.11
  • opencode-mem version: 2.13.0
  • Package manager: npm

Steps to Reproduce

  1. Install opencode-mem globally:

    npm install -g opencode-mem
  2. Attempt to start the web server using Bun:

    cd ~/.nvm/versions/node/v22.22.1/lib/node_modules/opencode-mem
    bun -e "
    import { startWebServer } from './dist/services/web-server.js';
    import { initConfig } from './dist/config.js';
    initConfig('$(pwd)');
    startWebServer({ port: 4747, host: '127.0.0.1', enabled: true })
      .then(s => console.log('Server started on', s.getUrl()))
      .catch(e => { console.error('Error:', e); process.exit(1); });
    "

Expected Behavior

The web server should start successfully on http://127.0.0.1:4747

Actual Behavior

The application crashes with the following error:

Error: 
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-darwin-arm64v8.node'
Require stack:
- /Users/user/.nvm/versions/node/v22.22.1/lib/node_modules/opencode-mem/node_modules/sharp/lib/sharp.js
- /Users/user/.nvm/versions/node/v22.22.1/lib/node_modules/opencode-mem/node_modules/sharp/lib/constructor.js
- /Users/user/.nvm/versions/node/v22.22.1/lib/node_modules/opencode-mem/node_modules/sharp/lib/index.js

Note: The error occurs in TWO locations:

  1. Main package: opencode-mem/node_modules/sharp/
  2. Dependency: opencode-mem/node_modules/@xenova/transformers/node_modules/sharp/

Root Cause

The sharp module has native bindings that need to be compiled specifically for macOS ARM64 architecture. The prebuilt binaries included in the default installation don't work correctly on Apple Silicon Macs.

Workaround / Solution

Manually reinstall sharp@0.33.0 in both locations:

# Fix 1: Main package
cd ~/.nvm/versions/node/v22.22.1/lib/node_modules/opencode-mem
npm install sharp@0.33.0 --save

# Fix 2: @xenova/transformers dependency
cd ~/.nvm/versions/node/v22.22.1/lib/node_modules/opencode-mem/node_modules/@xenova/transformers
npm install sharp@0.33.0 --save

After applying both fixes, the server starts successfully.

Additional Context

  1. Bun vs Node.js: opencode-mem requires Bun runtime (not Node.js) because it uses bun:sqlite. Attempting to run with Node.js produces: Error: require is not defined in ES module scope, you can use import instead followed by Error: Cannot find package 'bun:sqlite'

  2. Tried solutions that didn't work:

    • npm rebuild sharp - Did not resolve the issue
    • Installing with --platform=darwin --arch=arm64v8 flags - Did not work
    • Building from source with --build-from-source - Did not work
  3. What worked: Explicitly installing sharp@0.33.0 in both package locations

Suggested Fix

Consider one of the following:

  1. Update sharp dependency: Upgrade to sharp@0.33.0 or later in package.json, which has better macOS ARM64 support

  2. Add postinstall script: Add a postinstall script that checks for macOS ARM64 and rebuilds sharp automatically

  3. Update installation docs: Document this workaround for macOS ARM64 users until a permanent fix is implemented

  4. Use optional dependency: Consider making sharp an optional dependency or finding an alternative that doesn't require native bindings

Related Issues

This may be related to issues with sharp's prebuilt binaries for Apple Silicon. See: https://sharp.pixelplumbing.com/install


Impact: This affects all macOS users with Apple Silicon (M1/M2/M3/M4) chips who install opencode-mem via npm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions