Home > Net >  im trying to use my first css gem in rails project im getting an error
im trying to use my first css gem in rails project im getting an error

Time:11-14

Im trying to use my scss gem in rails project, but once i install the gem,im getting the error bellow:

file to import not found.

Here is my gemspec code

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require_relative "lib/scss_ninja/version"

Gem::Specification.new do |spec|
  spec.name          = "scss_ninja"
  spec.version       = ScssNinja::VERSION
  spec.authors       = ["tongoonamujera"]

  spec.summary       = "built to make styling look so easy"
  spec.description   = "Work still in progress"
  spec.homepage      = "https://github.com/tongoonamujera/scss_ninja.git"
  spec.license       = "MIT"
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")

  # spec.metadata["allowed_push_host"] = "https://github.com/tongoonamujera/scss_ninja.git"

  spec.metadata["homepage_uri"] = spec.homepage
  spec.metadata["source_code_uri"] = "https://github.com/tongoonamujera/scss_ninja.git"
  spec.metadata["changelog_uri"] = "https://tongoonamujera.github.io/scss_ninja/CHANGELOG.md"

  # Specify which files should be added to the gem when it is released.
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
  # spec.files = Dir.chdir(File.expand_path(__dir__)) do
  #   `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
  # end
  spec.files = Dir['app/**/*']
  spec.bindir        = "exe"
  spec.executables   = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
  spec.require_paths = ["lib"]

  # Uncomment to register a new dependency of your gem
  # spec.add_dependency "example-gem", "~> 1.0"

  # For more information and examples about making a new gem, checkout our
  # guide at: https://bundler.io/guides/creating_gem.html
  spec.add_runtime_dependency 'autoprefixer-rails', '~> 10.3', '>= 10.3.3.0'
  spec.add_runtime_dependency 'sassc', '~> 2.0'
end

I dont know whats wrong with my gem or either its a gemspec. The source code is found here on my github profile https://github.com/tongoonamujera/scss_ninja.git

CodePudding user response:

Seems you do not ship your lib directory into the gem contents:

spec.files = Dir['app/**/*']

And when Bundler tries to require the main gem file (lib/scss_ninja.rb), it is not there. Get the path of the installed gem directory:

gem info scss_ninja

and check what files have been installed with the gem. If the lib directory is not there, bingo.

You can include more files like so:

spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]

Also check the spec.files method description in gem guides.

  • Related