guard / listen

The Listen gem listens to file modifications and notifies you about the changes.
https://rubygems.org/gems/listen
MIT License
1.93k stars 247 forks source link

Error when using mac M1 running native arm #539

Closed uxxman closed 3 years ago

uxxman commented 3 years ago

Error Log

E, [2021-05-06T01:05:45.848957 #20864] ERROR -- : Exception rescued in listen-worker_thread:
Errno::EBADARCH: Bad CPU type in executable - /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rb-fsevent-0.10.4/bin/fsevent_watch
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rb-fsevent-0.10.4/lib/rb-fsevent/fsevent.rb:140:in `popen'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rb-fsevent-0.10.4/lib/rb-fsevent/fsevent.rb:140:in `open_pipe'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rb-fsevent-0.10.4/lib/rb-fsevent/fsevent.rb:39:in `run'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/adapter/darwin.rb:49:in `block in _run'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/thread.rb:26:in `rescue_and_log'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/thread.rb:18:in `block in new'
--- Thread.new ---
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/adapter/darwin.rb:49:in `_run'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/adapter/base.rb:79:in `block in start'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/thread.rb:26:in `rescue_and_log'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/thread.rb:18:in `block in new'
E, [2021-05-06T01:05:46.133285 #20864] ERROR -- : Exception rescued in listen-worker_thread:
Errno::EBADARCH: Bad CPU type in executable - /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rb-fsevent-0.10.4/bin/fsevent_watch
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rb-fsevent-0.10.4/lib/rb-fsevent/fsevent.rb:140:in `popen'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rb-fsevent-0.10.4/lib/rb-fsevent/fsevent.rb:140:in `open_pipe'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rb-fsevent-0.10.4/lib/rb-fsevent/fsevent.rb:39:in `run'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/adapter/darwin.rb:49:in `block in _run'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/thread.rb:26:in `rescue_and_log'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/thread.rb:18:in `block in new'
--- Thread.new ---
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/adapter/darwin.rb:49:in `_run'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/adapter/base.rb:79:in `block in start'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/thread.rb:26:in `rescue_and_log'
/opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/listen-3.5.1/lib/listen/thread.rb:18:in `block in new'
ColinDKelley commented 3 years ago

@uxxman I haven't seen this exact error before, but it feels a lot like the rb-fsevent gem was installed and natively built for a previous CPU (probably Intel on your old Mac) and then was migrated over. Does that sound possible? I've had similar problems when I upgraded OSX.

The fix in such cases is to uninstall the gem and reinstall it. As in:

gem uninstall rb-fsevent:0.10.4
gem install rb-fsevent:0.10.4
bundle install

but in this case you might just want to uninstall the entire version of Ruby from rbenv and then reinstall it. That will force all its gems to be reinstalled and rebuilt.

uxxman commented 3 years ago

@ColinDKelley thank you for the prompt response. I have tried uninstalling and reinstalling rb-fsevent but the issue remains. Even uninstalling the ruby and reinstalling it doesn't solve it

While researching I found this link https://qiita.com/kazutosato/items/6dea35e97f39d8d13e83#rails%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB

From google translate the gist is to change this

# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
  config.file_watcher = ActiveSupport::FileUpdateChecker

This indeed resolves the issue but are there any side-effects for this? Does this completely disables listen gem?

ColinDKelley commented 3 years ago

Oh, I see. The problem is in rb-fsevent. It contains a Mac binary executable inside the gem(!):

https://github.com/thibaudgg/rb-fsevent/blob/master/bin/fsevent_watch

I'm very surprised that's not a native build step. Can you please file a ticket over there? It's easy to spot that it doesn't support the ARM:

$ file fsevent_watch
fsevent_watch Mach-O 64-bit executable x86_64

Re: this change:

  config.file_watcher = ActiveSupport::FileUpdateChecker

I believe that setting tells Rails to not use listen to watch for file changes. If so, that would be a work-around rather than a fix for listen.

ColinDKelley commented 3 years ago

BTW the fsevent_watch gem does have instructions here for rebuilding:

https://github.com/thibaudgg/rb-fsevent#re-compilation

ColinDKelley commented 3 years ago

And it looks like there's already an issue there:

https://github.com/thibaudgg/rb-fsevent/issues/87

as well as a PR:

https://github.com/thibaudgg/rb-fsevent/pull/88

uxxman commented 3 years ago

Thank you @ColinDKelley. I will follow the issue there 👍🏻

thibaudgg commented 3 years ago

rb-fsevent version 0.11.0 has been released with mac M1 support, please give it a try!

ColinDKelley commented 3 years ago

@thibaudgg Excellent! Thank you for letting us know here.

shailscript commented 3 years ago

@ColinDKelley I ran into the same issue and I am using the latest version of listen gem, any plans on updating the gem so it can use rb-fsevent version 0.11.0?

ColinDKelley commented 2 years ago

@shailscript The listen gemspec is already compatible with that version. From the gemspec:

  gem.add_dependency 'rb-fsevent', '~> 0.10', '>= 0.10.3'

So you can add version 0.11.0 to your Gemfile. Likely you can just do

bundle update rb-fsevent

Please respond back here to let us know how that works for you.

shailscript commented 2 years ago

Yeah updating just rb-fsevent works well, as you suggested 👍