Jason Sevilla
Jason Sevilla

Reputation: 7

How to fix "`require_relative': cannot load such file" cannot load - Ruby

Tried to solve this on my own and so far no luck...

Error below:

1: from bin/run:3:in `<main>'
bin/run:3:in `require_relative': cannot load such file -- /Users/jason/Development/code/First Project/bin/bin/environment.rb (LoadError)

What's in my bin folder:

#!/usr/bin/env ruby

require_relative './bin/environment.rb'

CLI.new.call

In my config folder:

require 'pry'
require 'httparty'

require_relative "./lib/api.rb"
require_relative "./lib/cli.rb"
require_relative "./lib/pokemon.rb"

Project Directory:

-->Firstproject
 ->bin
   -run
->config
   -environment.rb
 ->lib
   -api.rb
   -cli.rb
   -pokemon.rb
-gitignore
-Gemfile
-README.md

Upvotes: 1

Views: 1631

Answers (2)

Ammy Varela
Ammy Varela

Reputation: 1

Check that your environment.rb file lives in config folder, not in lib. So change it to

require_relative './config/environment.rb'

Upvotes: 0

Zach Tuttle
Zach Tuttle

Reputation: 2341

I think you just need to adjust the path to correctly reference your environment.rb source file:

#!/usr/bin/env ruby

require_relative '../config/environment.rb'

CLI.new.call

If you look closely where your environment.rb file lives, it is in the project_dir/config/environment.rb but your bin/run you are attempting to locate the file at ./bin/environment.rb which doesn't exist according to your Project Directory layout.

Upvotes: 2

Related Questions