Asset compiling crashing on server environment with: "NoMethodError: undefined method `[]' for nil:NilClass"
Asked Answered
B

4

20

I've been pulling my hair out for this one. I've always had a bad relationship with the asset-pipeline, it is always giving me trouble.. And today again..

When I try and compile my assets locally, everything is fine:

$ RAILS_ENV=production rake assets:precompile --trace

But when I deploy with Capistrano which does:

cd /var/www/xxx/releases/20140717164232 && ( RAILS_ENV=production bundle exec rake assets:precompile )

It crashes with the following error:

rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
  (in /var/www/xxx/releases/20140717164232/app/assets/stylesheets/application-sign-in.css)
/var/www/xxx/shared/bundle/ruby/2.1.0/gems/sprockets-2.11.0/lib/sprockets/sass_functions.rb:63:in `sprockets_context'

I seriously do not know how to debug this.. Locally I can't reproduce it and on my server the error is just not pointing me anywhere..

I've searched for the error and tried a couple things but nothing helped. Some say the error is going away by updating.. Or by adding the sprockets gem before the sass-rails gem.

My project is setup like the following; A regular rails 4 app with a gem containing assets representing a template. I use the following line to make sure everything is compiled:

config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.css *.js *.eot *.woff *.ttf *.svg)

Anyone that knows how to solve this, or how to debug it?

EDIT

Removing all asset-url() helper seems to work.. But again, no clue why..

Bobbysoxer answered 17/7, 2014 at 16:58 Comment(8)
Hmm ya that's odd. Are you declaring a sass variable in application-sign-in.css with []?Dou
No, I don't. I do make use of the asset-url() helper which seems to be creating the problem.Bobbysoxer
if you're using sass mark-up in that file, I'd rename it to application-sign-in.css.scssDou
Well, I really don't know what solved the issue.. First I've renamed all files to sass which had helpers in them.. Which first didn't work. Then removed the whole app and all deploys from the server and deployed in an empty directory, after that it was solved.. I think some old stuff was breaking something.. Either way, it works now, thanks!Bobbysoxer
Have you lokked at github.com/rails/sass-rails/issues/191? (Upgrading to gem 'sass-rails', '~> 4.0.3' fixed the issue for me)Reprovable
I had this issue 4 times in a row, on the fifth deployment it worked fine. I had no such issues regarding scss or image-url links. STRANGE!Praxis
Tim, I share your hate for the asset pipeline.Elise
github.com/sstephenson/sprockets/issues/540 - if you downgrade your sass-rails to 4.0.2 - then - bundle update sass-rails - it will downgrade sprockets as well - then rake assets:recompile . This worked in my case - a 2 year old bug-workaround. Later versions of Rails 4.x may solve it as well, but then you have to rewrite tons of other formerly-working code to meet the latest syntax-whims imposed - working code broken within a major-version (as usual).Reaves
G
45

I had the same issue and it turned out to be a css file containing asset-url that didn't have the .scss extension. Weirdly I could compile the assets locally but not on the server.

Gignac answered 27/11, 2014 at 22:22 Comment(5)
I got this error message when upgrading from Rails 3 to Rails 4. The error was indeed that one of the included files was named .css instead of .scss. No asset-url in it though.Diplomacy
You guys are a lifesaver. This was driving me crazy!Vomit
Thanks, my issue was with font-url in a .css changed it to .scss (rails 4)Monkhmer
If the problem was not having .scss, how did it work in Rails 3, then? Seems the goal would be to make later versions work better / easier.Reaves
Thank you thank you thank you. In my case it was that I added font_url to a css file :/ grrrCompunction
O
1

the problem is because of .css extension instead of .scss. I have changed it on .scss and it worked.

Orchid answered 3/5, 2015 at 17:10 Comment(0)
L
0

The following are scss helpers:

image-url 
font-url 
video-url 
audio-url 
javascript-url 
stylesheet-url 
asset-data-url

If you have one of these in a css file it is not normal. Sprocket will raise NoMethodError: undefined method `[]' for nil:NilClass when processing the file.

Solution 1: Remove all scss helper from this file.

or

Solution 2: Change file extension to scss.

Lulu answered 25/1, 2024 at 3:20 Comment(0)
H
-1

Heroku has a post about this. Precompile it locally and add all those files especially /public/assets/manifest.yml. Heroku should ignore pre compilation and proceed.

Halliday answered 5/4, 2015 at 3:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.