Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

ruby on rails - "uninitialized constant Sass::Script (NameError)"

I had first to change my Gemfile from (I deleted the comments to make the text shorter):

source 'https://rubygems.org'

gem 'rails', '4.2.0'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc


group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

to:

source 'https://rubygems.org'


gem 'rails',                '4.2.0'
gem 'sass-rails',           '5.0.1'
gem 'uglifier',             '2.5.3'
gem 'coffee-rails',         '4.1.0'
gem 'jquery-rails',         '4.0.3'
gem 'turbolinks',           '2.3.0'
gem 'jbuilder',             '2.2.3'
gem 'sdoc',                 '0.4.0', group: :doc

group :development, :test do
  gem 'sqlite3',     '1.3.9'
  gem 'byebug',      '3.4.0'
  gem 'web-console', '2.0.0.beta3'
  gem 'spring',      '1.1.3'
end

now when I try to run the rails server with rails server -b $IP -p $PORT I get following error message:

/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sass-rails-5.0.1/lib/sass/rails/helpers.rb:11:in `<top (required)>': uninitialized constant Sass::Script (NameError)
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sass-rails-5.0.1/lib/sass/rails.rb:8:in `require'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sass-rails-5.0.1/lib/sass/rails.rb:8:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sass-rails-5.0.1/lib/sass-rails.rb:1:in `require'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/sass-rails-5.0.1/lib/sass-rails.rb:1:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.5@global/gems/bundler-1.7.6/lib/bundler/runtime.rb:76:in `require'
    from /usr/local/rvm/gems/ruby-2.1.5@global/gems/bundler-1.7.6/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    from /usr/local/rvm/gems/ruby-2.1.5@global/gems/bundler-1.7.6/lib/bundler/runtime.rb:72:in `each'
    from /usr/local/rvm/gems/ruby-2.1.5@global/gems/bundler-1.7.6/lib/bundler/runtime.rb:72:in `block in require'
    from /usr/local/rvm/gems/ruby-2.1.5@global/gems/bundler-1.7.6/lib/bundler/runtime.rb:61:in `each'
    from /usr/local/rvm/gems/ruby-2.1.5@global/gems/bundler-1.7.6/lib/bundler/runtime.rb:61:in `require'
    from /usr/local/rvm/gems/ruby-2.1.5@global/gems/bundler-1.7.6/lib/bundler.rb:133:in `require'
    from /home/ubuntu/workspace/hello_app/config/application.rb:7:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `require'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `block in server'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
    from /home/ubuntu/workspace/hello_app/bin/rails:8:in `require'
    from /home/ubuntu/workspace/hello_app/bin/rails:8:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
    from /home/ubuntu/workspace/hello_app/bin/spring:13:in `require'
    from /home/ubuntu/workspace/hello_app/bin/spring:13:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>' 

I tried the running the servers before changing the Gemfile, and it works, so it must be because of the new changes. Also I'm aware in the error it says ruby-2.1.5, and in my Gemfile I put 4.2.0 but I have no clue how to change this, or if this is even the problem? i tried to add ruby '2.1.5' under the source line, nothing changed. Also I changed 'rails', '4.2.0' to 2.1.5 but then the update failed telling me Could not find gem 'rails (= 2.1.5) ruby' in the gems available on this machine.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As said here:

https://github.com/josh/sprockets-es6/issues/15

Use sass-rails v 5.0.2+. This should solve your issue. So in the gem file change:

gem 'sass-rails', '5.0.3'

or

gem 'sass-rails', '5.0.2'

Update:

As the link is down now so this issue is actually with the gem version 5.0.1 so just run:

bundle update sass-rails

which ultimately updates you saas-rails gem to the latest one. Or you can enter the version in your gemfile as specified above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...