Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby' #96

Closed
felicityfmn opened this issue Jan 30, 2018 · 22 comments

Comments

@felicityfmn
Copy link

This project is for Ruby version 2.4 and newer.
For Ruby versions < 2.4 please file an issue here.

What problems are you experiencing?

I keep getting this error message on the console even though I have the event machine gem installed and the require em/pure_ruby

Steps to reproduce

What's the output from ridk version?

Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'
C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- 2.4/rubyeventmachine (LoadError) from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/eventmachine-1.2.5-x64-mingw32/lib/rubyeventmachine.rb:2:in <top (required)>' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in require'
from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in rescue in require' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:39:in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/eventmachine-1.2.5-x64-mingw32/lib/eventmachine.rb:8:in <top (required)>' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in require'
from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in rescue in require' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:39:in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/faye-websocket-0.10.7/lib/faye/websocket.rb:10:in <top (required)>' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in require'
from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in rescue in require' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:39:in require'
from C:/Ruby24-x64/flutterbot/play.rb:3:in `

'

@larskanis
Copy link
Member

Although eventmachine is provided as x64-mingw platform gem, it doesn't support ruby-2.4 or 2.5 right now. So would recommend you to do the following:

  1. Open an issue at eventmachine to update their dependency to rake-compiler-dock-0.6 and to add ruby-2.4 and 2.5 binary support this way and ask them for a new x64-mingw release.
  2. Ask the people at eventmachine, how 'em/pure_ruby' is supposed to work.
  3. Use gem install eventmachine --platform ruby in the meantime.

@larskanis
Copy link
Member

This issue is forwarded to eventmachine here. Closing now. Thank you @felicityfmn !

@isaiasilva
Copy link

This problem always occurs ... No convincing answer yet

@Impeck
Copy link

Impeck commented Oct 24, 2018

gem uninstall eventmachine
gem install eventmachine --platform ruby

@reach2jeyan
Copy link

@Impeck It does not work with those commands?

Any probable solutions to these? I believe it only occurred with ruby version more than 2.5 but seems like even in 2.4 that I Installed, I have this error

@Impeck
Copy link

Impeck commented Oct 31, 2018

To solve the problem specified in the topic you need to run these commands:

gem uninstall eventmachine
gem install eventmachine --platform ruby

@khiav223577
Copy link

I have to check whether EventMachine is defined before require em/pure_ruby to prevent getting warnings.

require 'em/pure_ruby' if not defined?(EventMachine)

@EglomSostenes
Copy link

To solve the problem specified in the topic you need to run these commands:

gem uninstall eventmachine
gem install eventmachine --platform ruby

Para os BRs: "Resolveu o meu problema"

@pke
Copy link

pke commented May 7, 2020

require 'em/pure_ruby' if not defined?(EventMachine)

Where did you put this code @khiav223577?

@khiav223577
Copy link

require 'em/pure_ruby' if not defined?(EventMachine)

Where did you put this code @khiav223577?

@pke
I put it at the first line of config/boot.rb in the beginning.

But I use this patch currently:

# config/patch_eventmachine.rb
class Bundler::Runtime
  alias_method :require_without_patching_eventmachine, :require

  def require(*groups)
    begin
      require_without_patching_eventmachine(*groups)
    rescue LoadError => e
      if e.path == '2.5/rubyeventmachine' # when require '2.5/rubyeventmachine' fails
        super 'em/pure_ruby'
        retry
      end

      raise e
    end
  end
end
# config/boot.rb
require_relative 'patch_eventmachine'

...
...

@pke
Copy link

pke commented May 9, 2020

I am having this problem when using bundle exec jekyll s. Where would I apply your patch then?

@khiav223577
Copy link

I am having this problem when using bundle exec jekyll s. Where would I apply your patch then?

I know nothing about jekyll.
You could submit an issue on jekyll to ask for help.

@Neha5248
Copy link

Neha5248 commented Aug 24, 2020

Again n again getting below error
I try to connect cucumber and appium . But not able to do because of this issue

Ruby

@MSP-Greg
Copy link
Contributor

MSP-Greg commented Aug 24, 2020

@Neha5248

For Ruby 2.5 and later, try:

gem uninstall eventmachine
ridk exec pacman -Sy openssl
gem install eventmachine --platform=ruby

ridk exec pacman -Sy openssl updates MSYS2 and installs the MSYS2 openssl package. This may take a little while...

gem install eventmachine --platform=ruby installs EventMachine but forces compiling the gem

EventMachine's current x64-mingw32 gem is not compatible with Ruby 2.6 and later, and it was accidentally built without that information in the gemspec.

Ruby 2.5 and later use OpenSSL 1.1.1. Ruby 2.4 uses OpenSSL 1.0.2, which requires a different set of commands.

@Neha5248
Copy link

@MSP-Greg

Thank a lot it's working fine now :)

@reach2jeyan
Copy link

reach2jeyan commented Aug 25, 2020

If you are using windows

Go to this folder C:\Ruby24-x64\lib\ruby\gems\{version of ruby}\gems\eventmachine-1.2.5-x64-mingw32\lib

open this file eventmachine.rb

write this require 'em/pure_ruby' in the first line of code in the file
this will make it work with no issues.

@makubex88
Copy link

gem uninstall eventmachine
gem install eventmachine --platform ruby

this works on my end.

@vincerubinetti
Copy link

vincerubinetti commented Apr 18, 2021

For those running into this problem with Jekyll's live-reload (bundle exec jekyll serve --livereload), I tried combining several of the above solutions:

  1. Completely uninstall Ruby and MSYS2
  2. Install Ruby and MSYS2 with Ruby Installer Ruby+Devkit 2.7.2-1 (x64)
  3. gem uninstall eventmachine and choose all to uninstall
  4. ridk exec pacman -Sy openssl (run in Command Prompt, not Git Bash or some other shell)
  5. gem install eventmachine --platform ruby
  6. Open C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\eventmachine-1.2.7-x64-mingw32\lib\eventmachine.rb
  7. Insert require 'em/pure_ruby' if not defined?(EventMachine) at the top of the file

This ALMOST works, but it still crashes after a few reloads:

trace
#<Thread:0x0000000007c892c0 C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/live_reload_reactor.rb:41 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        7: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/live_reload_reactor.rb:44:in `block in start'
        6: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/eventmachine.rb:197:in `run'
        5: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:144:in `run_machine' 
        4: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:547:in `run'
        3: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:547:in `loop'        
        2: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:553:in `block in run'        1: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:595:in `crank_selectables'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:595:in `select': Bad file descriptor 
(Errno::EBADF)

Really wish this issue was fixed... upstream or wherever the problem lies.


EDIT: This solution actually seems to work for me. None of the above steps needed, just one line added to Gem file. It still seems to throw the same errors, but it doesn't prevent the site from being refreshed.

@SeaDude
Copy link

SeaDude commented Jun 12, 2021

Although eventmachine is provided as x64-mingw platform gem, it doesn't support ruby-2.4 or 2.5 right now. So would recommend you to do the following:

  1. Open an issue at eventmachine to update their dependency to rake-compiler-dock-0.6 and to add ruby-2.4 and 2.5 binary support this way and ask them for a new x64-mingw release.
  2. Ask the people at eventmachine, how 'em/pure_ruby' is supposed to work.
  3. Use gem install eventmachine --platform ruby in the meantime.

Interesting that this is still required a few years later.

  • Fresh install on Windows 10 following official Quickstart docs
  • Running:
    jekyll new eblog
    cd eblog
    bundle exec jekyll serve
  • Fails with:
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/servlet.rb:3:in `require': cannot load such file -- webrick (LoadError)
  • Ran bundle add webrick
  • Then bundle exec jekyll serve
  • Fails with:
Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'
                    ------------------------------------------------
      Jekyll 4.2.0   Please append `--trace` to the `serve` command
                     for any additional information or backtrace.
                    ------------------------------------------------
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/eventmachine-1.2.7-x64-mingw32/lib/rubyeventmachine.rb:2:in `require': cannot load such file -- 3.0/rubyeventmachine (LoadError)
  • Tried running bundle add rubyeventmachine
Could not find gem 'rubyeventmachine' in rubygems repository
https://rubygems.org/ or installed locally.
The source does not contain any versions of 'rubyeventmachine'
  • Found this Github issue and ran gem install eventmachine --platform ruby
  • Now bundle exec jekyll serve serves up the website as intended.

@spaquet
Copy link

spaquet commented Dec 19, 2021

What worked for me on Apple Silicon M1 and Rails 6.1

  • Full uninstall of eventmachine: gem uninstall -aIx eventmachine followed by a rm -rf vendor/cache
  • Add eventmachine in the project Gemfile and forcing it to be from the master branch latest like this gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git', :branch => 'master'
  • Run bundle install

@Lojlk
Copy link

Lojlk commented Jan 1, 2022

@Neha5248

For Ruby 2.5 and later, try:

gem uninstall eventmachine
ridk exec pacman -Sy openssl
gem install eventmachine --platform=ruby

ridk exec pacman -Sy openssl updates MSYS2 and installs the MSYS2 openssl package. This may take a little while...

gem install eventmachine --platform=ruby installs EventMachine but forces compiling the gem

EventMachine's current x64-mingw32 gem is not compatible with Ruby 2.6 and later, and it was accidentally built without that information in the gemspec.

Ruby 2.5 and later use OpenSSL 1.1.1. Ruby 2.4 uses OpenSSL 1.0.2, which requires a different set of commands.

Hi Greg, I followed your steps (am using Ruby 2.7.5) and "bundle exec jekyll serve --livereload" was met with Could not find eventmachine-1.2.7-x64-mingw32 in any of the sources. Any solutions? Thanks

@FredyRosero
Copy link

I had that error when I run bundle exec jekyll serve --livereload --trace on Jekyll.4.2.1-Ruby.3.0.3p137(mingw)-Windows. I ran gem install eventmachine --platform=ruby and it compiled at C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\eventmachine-1.2.7 but when you run bundle install it creates also C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\eventmachine-1.2.7-x64-mingw32 🤔. The command bundle info eventmachine gives me C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/eventmachine-1.2.7-x64-mingw32 and that's confimed in the Gemfile.lock with the line eventmachine (1.2.7-x64-mingw32). So I changed that line for eventmachine (1.2.7) and then the output of bundle info eventmachine gives me C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/eventmachine-1.2.7 and finally the command bundle exec jekyll serve --livereload --trace worked ✔️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests