how do I make webpack-dev-server respect rbenv configuration? - ruby-on-rails

I've got an existing rails app using webpacker and I just attempted to migrate from rvm to rbenv. Everything appeared to be working in my automated tests, but when I try to fire up bin/webpack-dev-server, it seems to want to use the System ruby rather than the one specified by my Gemfile (and my .ruby-version). It tells me:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in 'require': cannot load such file -- bundler/setup (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in 'require'
from ./webpack-dev-server:12:in '<main>'`
As near as I can tell, this is happening because of the following line at the top of the webpack-dev-server script:
#!/usr/bin/env ruby
but I do not know how to make it work properly with rbenv. When I run rails webpacker:check_binstubs, it does not show me any errors, but clearly there is a problem. Did I miss a step in removing rvm? Please help.

Related

Ruby issue while configuring sensu checks

I have sensu server and sensu-client Installed on one machine (centos) and installed the the plugins through gem.
Everything was good when I run the check_ping.rb from the command line, but When I configure the same check in /etc/sensu/conf.d/ and check in the UI I am getting this ruby issue;
gem install sensu-plugins-network-checks
I have ruby installed of 1.9.3 version
and configured EMBEDDED_RUBY=true
when I check the UI the below is the error I am facing
/opt/sensu/embedded/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- net/ping (LoadError)
from /opt/sensu/embedded/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p551/gems/sensu-plugins-network-checks-0.2.4/bin/check-ping.rb:31:in `<main>'
Sensu::Plugin::CLI: ["Not implemented! You should override Sensu::Plugin::CLI#run."]
Can someone help with this?
It is a common issue that Gems get installed but not to the embedded ruby which you are using.
what you want to do is /opt/sensu/embedded/bin/gem install net/ping
so it is in the right place.
The alternative option for this would be to edit /etc/default/sensu file and change embedded ruby to false then it would use your regular ruby and the corresponding gems.

Rails - script/server boot up

Can someone help me out with something seemingly simple? My newness to Ruby on Rails is the reason, no doubt. I cannot start up the server. It looks like the boot file cannot be located but I'm nor sure at all.
There are several versions of ruby here, related to installing rvm:
which -a ruby
/Users/me/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
/Users/me/.rvm/bin/ruby
/usr/local/bin/ruby
/usr/bin/ruby
Probably need to remove some?
Using Rails 3.2.9 with Ruby 1.9.3 on a Mac Mini
Thanks!
cd [rails project dir]
$ script/server
/Users/me/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require':
cannot load such file -- script/../config/boot (LoadError)
from /Users/me/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from script/server:2:in `'
This isn't the issue you are getting. script/server still works, what you are experiencing is an issue with the gems you are trying to use. What you might try is running rails s --trace, see what gems are causing the issue and manually reinstalling them. From the looks of it, it's just an issue with a lone gem with dependencies in 1.9.1.
With Rails 3+ you get access to the rails command line scripts so instead of calling script/server you just run rails server or rails s for short.

Newly installed gem not loading in RVM

I am having some issues getting Machinist and Sham working for my new rails project. In the past I've used Factory-girl.
I've got rvm installed and I installed machinist by adding it to my gemfile.
When I run rake i get the following error...
/Users/liamnorton/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require': no such file to load -- sham (LoadError)
Which is caused by the line at the top of my blueprints.rb file
require 'sham'
Can someone please help me get this working. I've had issues with RVM in the past and don't want to be imploding and rebuilding if I don't have to!!
Well surprise surprise, including the line gem 'sham' in my gemfile worked!
I thought that Sham was dependent on Machinist, and therefore would be install when running bundle install but no. Machinist 2 wipes it's hands clean.

`require': cannot load such file on running rails --help on brand new install

This is getting quite frustrating. I've eventually resorted to completely removing RVM, and reinstalling from scratch, as a normal user, so restricted to my /home.
After reinstall, I've run gem update --system and gem install rails.
Then I run rails --help, and get the following error:
rails --help
/home/anthony/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- /home/anthony/config/boot (LoadError)
from /home/anthony/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from script/rails:5:in `<main>'
Apparently rails thinks it should be loading a file /home/anthony/config/boot. It looks like the load path is screwed.
I've searched this out, and most people getting this error solve it with gem update --system (which I've one as above), or can at lest run rails -- or rails new . None of these work.
Final System info:
https://gist.github.com/1424644
Please help!
This may be totally a red herring, but it looks like your rails is in a different gemset - "campingground" - than either gem or ruby, which are in your default gemset. I'm not sure if this will cause the issue you're seeing or not - I believe it's OK if you're using the campingground gemset rvm use ruby-1.9.3-p0#campingground, but not if you're using the default gemset rvm use ruby-1.9.3-p0 because I believe that gemsets all inherit the default gemset, but not vice versa. I've had some issues with the bin launchers of ruby helpers (like the rails command) barfing all sorts of confusing load errors, which are often this very issue. Again, not sure if helpful, but I'd share that shot in the dark.

Rails 2.x mongrel won't start after upgrading to rails 3. -- mongrel_rails (MissingSourceFile)

After upgrading my Rails install to Rails 3 on OS X, I’ve had problems running my Rails 2.x development sites with Mongrel. WEBrick seems to work, but I really would like to have the nice output of Mongrel for debugging.
After running $ script/server I get this:
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load': no such file to load -- mongrel_rails (MissingSourceFile)
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:49:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:49:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:49:in `gem_original_require'
So far, here’s what I’ve tried:
$ sudo gem update system
$ sudo gem update
$ sudo gem uninstall mongrel
$ sudo gem install mongrel --include-dependencies
$ which mongrel_rails
→ /usr/bin/mongrel_rails
$ mongrel_rails start
→ Success, but no stdout
$ which mongrel_rails
→ /usr/bin/mongrel_rails
$ rails _2.0.2_ test
→ Fresh application has same problem.
OS: OS X.6.x
Rails: 3.0.5 (problems are with Rails 2.x apps)
gem -v: 1.6.1
Mongrel: mongrel (1.1.5)
I’ve read EVERY Google result on "-- mongrel_rails (MissingSourceFile)"; there aren’t many.
Can anyone here tell me how to proceed in debugging this? Thanks!
UPDATE:
I’ve now tried installing older versions of the gem and specifying those in my Rails 2.x site’s config/environment.rb file. I’ve tried 1.1.5, 1.1.4, and 1.2.0pre.
None of these makes the slightest bit of difference.
Since the executable in in usr/bin I’m wondering if it’s a file ownership issue that got screwed up on my Rails 3 install and if one of the files isn’t getting my paths when it runs?
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb
is owned by admin / root, so that should be OK, right?
Could it be a problem with active_support!?
Here’s the code from dependencies.rb that’s throwing the error:
484 class Object
485
486 alias_method :load_without_new_constant_marking, :load
487
488 def load(file, *extras) #:nodoc:
489 Dependencies.new_constants_in(Object) { super(file, *extras) }
490 rescue Exception => exception # errors from loading file
491 exception.blame_file! file
492 raise
493 end
...
This is getting a file not found error, so it’s not looking where I know the file to be…
Running mongrel_rails on command line works…
Which mongrel_rails shows it in usr/bin,
So what’s the problem?
I have got the same problem and found the reason.
This happens because new version of RubyGems(1.6.2) does not add 'any_gem/bin' to ruby load path ($LOAD_PATH) when you require "any_gem".
For example in RubyGems version = 1.4.1 this works fine. After I require 'mongrel' I can see in load path next:
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/bin
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/lib
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/ext
With new version (1.6.2) I can see only:
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/lib
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/ext
That's why ruby cannot find 'mongrel_rails'.
You need to add "/usr/bin" to your load path. Perhaps something broke in it?
The best way to fix it is to add:
$:.push("/usr/bin/")
Somewhere before it breaks. Probably by itself in a config/preinitializer.rb file if you don't have one.
OK, here's ONE answer. I got mongrel to boot...but it's hacky, and doesn't solve the real problem...but at least for NOW I can get back to work on this project.
Here's what I did...YES..it's HACKY.
I edited the file throwing the error...dependencies.rb
I added a hook to call out the specific path to mongrel rails if that was the file it was trying to load.
def load(file, *extras) #:nodoc:
if file == "mongrel_rails"
file ="/usr/bin/mongrel_rails"
end
Dependencies.new_constants_in(Object) { super(file, *extras) }
rescue Exception => exception # errors from loading file
exception.blame_file! file
raise
end
Again, I would really like to fix the underlying problem here...but this at least let me boot up.
I would definitely look in to using RVM for running multiple gem versions simultaneously locally. I ran into a lot of quirks when I was attempting to run multiple versions like you are with sudo gem installs of everything.
Now it's as simple as rvm ree#my_app_1, and installing completely separate gems there, then switching to a different app and using rvm ree#my_app_2
ree is an alias for my install of ruby enterprise version, you could just as easily do it with ruby 1.9, 1.8.x, etc.
In each of my application's root directories I have a .rvmrc file that reads simply:
rvm ree#my_app --create
So that every time I switch to that directory, the gemset is automatically swapped for me.
I wasn't aware there was Rails 3 mongrel support.
Most people use Thin (you can enable it by specifying gem 'thin' in your Gemfile then launching rails server thin / Webrick these days.
If this is for hosting then there's nginx and Passenger that'll help with that.
I ran into the same problem -- got my app going by running "mongrel_rails" from the project directory (instead of "script/server").
This is the thread where you are able to find the best answer to the mongrel_rails (MissingSourceFile) error. I just want to conclude here how I solved the problem, using stuff in this thread.
The simplest solution I could figure out how to do was to downgrade RubyGems by typing
(sudo) gem update --system 1.4.1
This lets me run the old 2.1.0 app (thanks Max Shytikov), but there's probably a lot of bugfixes that I'm missing by running the old version of rubygems. The error is probably a blunder by the mongrel gem developers (I guess).
Anyway if you just want to run your app using mongrel do it like this. If you insist on having the newest version of rubygems, you can just run your app with
script/server webrick
But I've found that webrick is a fair bit slower, so I prefer mongrel. If anyone has got a better solution for this problem, please let me know.
I ran into the same error. The fix is to add the mongrel "bin" directory to the $LOAD_PATH. Other posts describe how to do it by modifying source code, but since I share source code with other developers, I prefer to set the RUBYLIB environment variable instead.
$ export RUBYLIB=/Users/edwingo/.rvm/gems/ruby-1.8.7-p302#junction/gems/mongrel-1.1.5/bin
This causes the MRI ruby runtime to prepend that to the $LOAD_PATH.
Detailed explanation: MRI is unable to find 'mongrel_rails' because it is not on the $LOAD_PATH. I am using RVM and when I installed mongrel into a gemset, for some reason the $LOAD_PATH does not include the corresponding "bin" directory where 'mongrel_rails' lives. When not using RVM and after installing mongrel into the system gems, the "bin" directory does appear on the $LOAD_PATH so it all works.

Resources