ruby-on-railsrubyrbenvexecjs

ExecJS::RuntimeError in Rails App when switched to rbenv


Recently switched from rvm to rbenv on macOS. Everything bundles ok, but when I boot up the app locally and then access the app in the web browser, it throws this error:

ExecJS::RuntimeError

Everything was working ok while I was using rvm. So I'm wondering if I need to do something special since I'm now using rbenv?

I've searched around and experimented for how to fix this. Most answers are 7+ years old. I've seen suggestions of including execjs as well as therubyracer within my Gemfile. I tried including both in my Gemfile, but unfortunately that did not do the trick.

Ruby version: 2.7.4

Rails version: 6.1

Update some things that show up in the console:

dyld[32305]: Library not loaded: @loader_path/../../../../opt/icu4c/lib/libicui18n.73.dylib

Referenced from: /opt/homebrew/Cellar/node@18/18.17.1/bin/node

Reason: tried: '/opt/homebrew/Cellar/node@18/18.17.1/bin/../../../../opt/icu4c/lib/libicui18n.73.dylib' (no such file), '/usr/local/lib/libicui18n.73.dylib' (no such file), '/usr/lib/libicui18n.73.dylib' (no such file, not in dyld cache)

ActionView::Template::Error ():

(execjs):1


Solution

  • What finally fixed it for me was running these commands:

    brew cleanup
    brew upgrade
    

    Running brew upgrade will upgrade ALL packages, so may not be what you want. But it worked for me.

    Reference: dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac