# macOS: dlopen: mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')

**Code:** `mach-o file, but is an incompatible architecture` · **Category:** macOS · **Seen on:** macOS, Node.js

A library or binary was built for a different CPU architecture than the process loading it.

## Meaning

The process is arm64 but the library is x86_64 (or the other way). Reinstall the dependency for arm64 (Homebrew in /opt/homebrew), rebuild native modules (`npm rebuild`, `pip install --force-reinstall`), or run the whole stack under Rosetta consistently (`arch -x86_64`). Mixing Intel and ARM Homebrew prefixes causes this often.

## Common causes

- Native module compiled for x86_64 under an arm64 Node/Python
- Libraries from /usr/local (Intel) used by arm64 apps
- Universal binary missing a slice
- Docker platform mismatch
- Old prebuilt wheels

## Quick fix

1. Rebuild native modules: `npm rebuild` / `pip install --no-binary :all: PKG`
2. Reinstall Homebrew packages under /opt/homebrew
3. Run everything in Rosetta: `arch -x86_64 zsh`

## Detailed fix by platform

### macOS

1. `lipo -info /path/lib.dylib` and `file $(which node)`

## How to diagnose

1. **Arch** — Process vs library?
2. **Prefix** — /opt/homebrew vs /usr/local?
3. **Rebuild** — Native modules?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/macos/mach-o-incompatible-architecture)
