Ruby 'requires' are throwing NoMethodError's, stack trace shows Unix paths on a Windows machine

拟墨画扇 提交于 2019-12-12 04:47:52

问题


Trying to run a ruby script, but it's failing on the 'require' statements, throwing a strange error:

Code:

require "rubygems"
require "bundler/setup"
require_relative "plugins/pivotal_rabbitmq_plugin/pivotal_rabbitmq_plugin.rb"
require "newrelic_plugin"

module PivotalAgent
  NewRelic::Plugin::Config.config_file=File.dirname(__FILE__) + "/config/newrelic_plugin.yml"
  NewRelic::Plugin::Run.setup_and_run
end

Command:

ruby pivotal_agent.rb

Error:

/usr/share/rubygems/rubygems/path_support.rb:78:in `path=': undefined method `+' for nil:NilClass (NoMethodError)
        from /usr/share/rubygems/rubygems/path_support.rb:34:in `initialize'
        from /usr/share/rubygems/rubygems.rb:325:in `new'
        from /usr/share/rubygems/rubygems.rb:325:in `paths'
        from /usr/share/rubygems/rubygems.rb:348:in `path'
        from /usr/share/rubygems/rubygems/specification.rb:872:in `dirs'
        from /usr/share/rubygems/rubygems/specification.rb:750:in `stubs'
        from /usr/share/rubygems/rubygems/specification.rb:938:in `find_inactive_by_path'
        from /usr/share/rubygems/rubygems.rb:186:in `try_activate'
        from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
        from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:39:in `require'
        from pivotal_agent.rb:2:in `<main>'

Any ideas what might be causing that? My initial hunch is that it has something to do with the file paths it's looking at being formatted for Unix while this is running on a Windows machine, but I've added Ruby to PATH, so I don't know why it would be looking there rather than where Ruby is actually installed (C:\Ruby22-x64).

EDIT: To clarify, the first require (for 'rubygems') doesn't throw an error, but both the other requires and the require_relative all throw a similar one.


回答1:


Not 100% sure why, but removing the 'ruby' from the start of the command fixed it. So just running

my_script.rb

works fine, but running

ruby my_script.rb

gives the above stack.



来源:https://stackoverflow.com/questions/45554879/ruby-requires-are-throwing-nomethoderrors-stack-trace-shows-unix-paths-on-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!