What does "<top (required)>" mean in a Ruby stack trace?

If everything you required is correct, it could mean that you're trying to create a class with a name that already exists for a module. For example the following file :

class Test
end

Will raise : <top (required)>': Test is not a class (TypeError)

Because Test is implicitely a module.


It's the top level of a file i.e. whatever gets run when the file is required.
So if something fails during the setup of a library (for example some required file isn't found) it will show up in the stacktrace like that.


I had the same problem. Solved it by converting .rb files encoding to UTF-8-BOM using Notepad++.


I ran into this error of <top (required)> when I was doing the tutorial in the book "Jump Start Sinatra."

I got rid of the error by making sure that I ran sudo gem install <GEM_IN_YOUR_FILE>. So in my case I had a main.rb and in that file I had this

require 'sinatra'
require 'sinatra-contrib'

So I went back into the root of my project and ran sudo gem install sinatra and sudo gem install sinatra-contrib and then my project worked fine.

Your errors will vary, but because this is what I found when I searched on Google, I know others will come here for similar reasons. And I offer this solution to at least get you thinking in the right direction since this worked for me.

Tags:

Ruby