ardavis
ardavis

Reputation: 9895

Precompiling Assets Failure During Deployment

I am using Capistrano to precompile my assets during deployment, and I am getting an error that isn't very useful to me.

* executing "cd -- path/to/releases/20130507161214 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"

*** rake aborted!
*** wrong argument type nil (expected Data)
*** (in /path/to/app/assets/javascripts/application.js)
*** /path/to/gems/therubyracer-0.11.4/lib/v8/context.rb:67: in 'New'

Here is my application.js that is referred:

//= require jquery
//= require jquery_ujs
//= require bootstrap

Update

So I tried to just remove application.js entirely and run it again, but then it complained about another js file of mine (but the same non-helpful error). Then I removed all of my js files and it started to complain about my css files.

If all js and css files are removed, the precompile does succeed (but obviously without my needed js and css files).

I am using .js.coffee and .css.scss for all of my non-image assets.

Update

@TomDavies answer did indeed help me, but still having the issue. During deployment, it was just failing on precompile and not giving me information. So I did what Tom mentioned, I precompiled on my development machine, but in the production environment, and noticed I was also having issues.

The error it gave me was "Unexpected INDENT", but it would not tell me a line number, just a file name...

I eventually discovered I was missing a comma in my ajax request. Apparently it works without it in the development environment, just doesn't precompile without it...

Here is what I had:

$.ajax 'some/url'
  success:
    alert 'yay!'

Here is what I needed:

$.ajax 'some/url',
  success:
    alert 'yay!'

Notice the comma at the end of the top line... now precompiles great in development. I thought for sure that fixing the errors during precompile on the development machine (but production environment) would fix the deployment issue, but to no avail. It is still failing with the same error at the top wrong argument type nil (expected Data).

tl;dr

I am able to run the rake assets:precompile RAILS_ENV=production on my development machine, doesn't work on the production machine, gives the error at the top. Not sure how to debug this one.

Upvotes: 3

Views: 821

Answers (3)

Brendon McLean
Brendon McLean

Reputation: 416

I would also look to using Node.js as the ExecJS runtime. There are several documented issues with TheRubyRacer and memory management (https://github.com/cowboyd/therubyracer/issues/350) and it seems that the project has been abandoned (https://github.com/cowboyd/therubyracer/pull/348).

Assuming you have the latest Node.js installed, you can prepend/append EXECJS_RUNTIME="Node" to your precompile task:

rake assets:precompile RAILS_ENV=production EXECJS_RUNTIME="Node"

As a bonus, this sped up asset compilation by an order of magnitude.

Upvotes: 0

DennisCamp
DennisCamp

Reputation: 126

This looks like a possible gem problem, since it's failing on the application.js file and your content looks correct. Which version of Ruby are you working with? If you have switched different versions, you may want to clear out your gems directory and reinstall them from scratch. I have experienced issues with gems installed under one Ruby version leaving fodder behind that causes strange things to happen under another version.

Upvotes: 1

TomDavies
TomDavies

Reputation: 672

Your file should be called application.scss if you want to import other scss from it.

I'm not sure of you exact error, but for asset pipeline issues you should always try compiling them locally in development. The errors are usually much more obvious that way and you can trial / error more easily. Here are some steps I usually leave in my config/environments/development.rb for getting asset precompilation to work locally:

  # NOTE: To test asset pipeline in dev uncomment the following configs and run:
  #
  # $ RAILS_ENV=development rake assets:precompile
  #
  # It is recommended you rm -rf public/assets when you are finished or this may affect
  # your local dev environment
  #
  # config.assets.compress = true
  # config.assets.compile = false
  # config.assets.digest = true

And here is a gist of the same:

https://gist.github.com/atomgiant/5438672

Upvotes: 1

Related Questions