[Solved] rails on M2: dyld[…]: missing symbol called – Node.js

by
Ali Hasan
apple-m1 macos mysql2 node.js ruby-on-rails

The Problem:

After upgrading a Rails project from 5 to 6, running Rails commands on an M2 Mac results in a "dyld: missing symbol called" error when using the mysql gem. This issue does not occur when using SQLite. The issue persists despite attempts to reinstall Node and Yarn, switch to a x64 Node version, and remove node_modules.

Q&A

How to fix rails on M2 missing symbol called?

Re-install the mysql2 gem with specific settings: –with-mysql-config=\((brew –prefix mysql)/bin/mysql_config –with-ldflags="-L\)(brew –prefix zstd)/lib -L$(brew –prefix openssl)/lib" –with-cppflags=-I$(brew –prefix openssl)/include

How to go about fixing missing symbol errors?

Compare working and non-working versions of your app to identify the cause, try different machines, delete gems, or use different versions to narrow down the issue.