Search code examples
javascriptruby-on-railsrubywebpackvite

Rack app error handling request { GET /vite-dev/@vite/client }


After starting the rails server and vite dev server, when I try to access the rails application from browser I am getting this error:

#<NoMethodError: undefined method `then' for #<Array:0x00007fb072a3b2c0>>
/home/.rvm/gems/ruby-2.5.3/gems/rack-proxy-0.7.6/lib/rack/proxy.rb:27:in `extract_http_request_headers'
/home/.rvm/gems/ruby-2.5.3/gems/rack-proxy-0.7.6/lib/rack/proxy.rb:115:in `perform_request'
/home/.rvm/gems/ruby-2.5.3/gems/vite_ruby-3.2.14/lib/vite_ruby/dev_server_proxy.rb:20:in `perform_request'
/home/.rvm/gems/ruby-2.5.3/gems/rack-proxy-0.7.6/lib/rack/proxy.rb:87:in `call'```

The versions from my system are below:
ruby is 2.5.3
rails is 5.2.2
node is 14.21.2
npm is 6.14.17
yarn is 1.22.19
vite_ruby is 3.2.14
vite_rails is 3.0.14

The configurations from my system are below:
package.json -
`{
  "devDependencies": {
    "vite": "^4.1.3",
    "vite-plugin-ruby": "^3.1.3"
  },
  "dependencies": {
    "axios": "^1.2.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }
}`


I tried downgrading the puma and vite and node versions but no luck.
I have posted the config file above as well.
even tried the host as 127.0.0.1 and 0.0.0.0.

Solution

  • The then method was introduced in Ruby 2.6. But you are using Ruby 2.5.3.

    Which means the rack-proxy gem that raises the error is simply not compatible with your old Ruby version.

    Ruby 2.5 reached end-of-life about 2 years ago. Therefore, I suggest updating to an up-to-date and still maintained Ruby version. Which means Ruby 3.0, because Ruby 2.7 will reach end-of-life in about 7 weeks, too.

    But that will lead to another problem. You are still running Ruby on Rails 5.2 which is outdated for a while already. And Ruby on Rails 5.2 is not compatible with Ruby >= 2.7. That means you will need to update Ruby on Rails too.

    Another option might be to try removing the dependency on the rack-proxy gem from your application or to downgrade rack-proxy to a version that was up-to-date when Ruby 2.5 was still maintained, like ~> 0.6.0.