node.jsruby-on-railsmacosapple-m1mysql2

rails on M2: dyld[...]: missing symbol called


I upgraded my Rails project from 5 to 6 and now Rails commands throw this error on my M2 mac:

dyld[...]: missing symbol called

It looks like some sort of problem with Node and mysql gem. When I create new project with SQLite, everything runs fine:

% rbenv versions
* 3.1.2 
% rails -v                    
Rails 6.1.7.3
% rails new test
% rails s

But when I do the same with mysql db, the installation ends on webpacker install:

% rails new test2 -d mysql
...
Bundle complete! 17 Gemfile dependencies, 81 gems now installed.
  run  bundle binstubs bundler
  rails  webpacker:install
dyld[25919]: missing symbol called

I have the lastest mysql2 gem version:

gem "mysql2", '~> 0.5.5'

I tried all the other tricks that I found: reinstalling node, yarn, switch to x64 node version, removing node_modules.. all of it. No success so far


Solution

  • Ok, I found a solution. It was indeed problem with mysql2 gem. Standard installation of this gem doesn't work for mysql installed by homebrew.

    If you installed the gem previously and it causes problems, uninstall this specific version first:

    gem uninstall mysql2 -v 0.5.5
    

    Then install it again, but with these settings:

    gem install mysql2 -v '0.5.5' -- --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
    

    Istead of 0.5.5, fill in the version of the gem you need to install. I used 0.5.5 as it's the latest version at this moment. "brew --prefix ..." will add paths to specific files automatically.

    I realize this was very specific problem. Sadly, the "missing symbol called" could mean anything. If you see the same error, I would recommend finding a version of your app that works and comparing the differencies between them. It could mean trying it on a different machine, deleting some gems, trying different versions.. That should point you in the right direction.