Missing Import Errors in Ruby
Ruby's LoadError: cannot load such file and NameError: uninitialized constant indicate a missing require or an uninstalled gem.
require vs require_relative
# require — searches $LOAD_PATH and gems
require 'json'
require 'httparty'
# require_relative — relative to current file
require_relative 'lib/helpers'
require_relative '../models/user'Install the Gem
# Direct install
gem install httparty
# Or add to Gemfile
# Gemfile
gem 'httparty'
bundle installBundler Require
With Bundler, use Bundler.require to auto-require all gems:
require 'bundler/setup'
Bundler.requireOr require gems individually:
require 'bundler/setup'
require 'sinatra'
require 'sequel'$LOAD_PATH
Add directories to the load path:
$LOAD_PATH.unshift(File.join(__dir__, 'lib'))
require 'my_module'Standard Library Requires
Some stdlib modules need explicit require:
require 'net/http' # HTTP client
require 'uri' # URL parsing
require 'csv' # CSV parsing
require 'fileutils' # File operations
require 'open3' # Process spawning
require 'set' # Set data structureGem Name vs Require Name
Sometimes they differ:
# gem install aws-sdk-s3
require 'aws-sdk-s3' # Same
# gem install pg
require 'pg' # Same
# gem install activerecord
require 'active_record' # Different!Bugsly captures LoadError exceptions with the attempted file path, making it immediately clear which gem or file is missing in your production environment.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
Fix Missing Import in Perl
Resolve 'Can't locate module' and 'Undefined subroutine' errors in Perl, covering use, require, CPAN modules, and @INC issues.
Read moreHow to Fix Validation Error in Clojure
Struggling with Validation Error in Clojure? This guide explains why it happens and how to resolve it quickly.
Read moreFix AuthenticationError Error in Flask — When Deploying
Learn how to fix the AuthenticationError error in Flask when deploying. Step-by-step guide with code examples and solutions.
Read moreHow to Fix File Not Found Error in C#
Learn how to fix the File Not Found Error in C#. Step-by-step guide with code examples.
Read more