Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't dump anonymous class #242

Closed
bigardone opened this issue Sep 6, 2014 · 18 comments
Closed

Can't dump anonymous class #242

bigardone opened this issue Sep 6, 2014 · 18 comments

Comments

@bigardone
Copy link

Hi!
I'm playing around with Rails 4.2 beta, and on my development environment everything works fine.
But when trying to deploy it to Heroku it throws the following warnings:

   Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   I, [2014-09-06T08:40:56.175939 #1419]  INFO -- : Writing /tmp/build_e9eb8553-5a26-45bb-9b07-4a29d52eebf5/public/assets/application-c38a0ad55f5bf7591155c6a2bde206ae.js
   Warning. Error encountered while saving cache 8c16b074fa857dd7330d237ba37aa77ede63da1b/application.css.sassc: can't dump anonymous class #<Class:0x007fe009798f88>
   Warning. Error encountered while saving cache bc4c85f8e508d5e8d8306f180bfa2a3ff0b38670/normalize.cssc: can't dump anonymous class #<Class:0x007fe009798f88>
   Warning. Error encountered while saving cache 972b158d9548d695d24c06b6eebce83723bf8c73/_bourbon.scssc: can't dump anonymous class #<Class:0x007fe009798f88>
   Warning. Error encountered while saving cache ec194de8e45c18d895fbaea9472611503479082e/_prefixer.scssc: can't dump anonymous class #<Class:0x007fe009798f88>
   Warning. Error encountered while saving cache ec194de8e45c18d895fbaea9472611503479082e/_px-to-em.scssc: can't dump anonymous class #<Class:0x007fe009798f88>
   Warning. Error encountered while saving cache ec194de8e45c18d895fbaea9472611503479082e/_asset-pipeline.scssc: can't dump anonymous class #<Class:0x007fe009798f88>
   Warning. Error encountered while saving cache d6bf3497cb4eb5cc1717b3e31f3a48c562f51bf2/_convert-units.scssc: can't dump anonymous class #<Class:0x007fe009798f88>
   Warning. Error encountered while saving cache d6bf3497cb4eb5cc1717b3e31f3a48c562f51bf2/_gradient-positions-parser.scssc: can't dump anonymous class #<Class:0x007fe009798f88>
   Warning. Error encountered while saving cache d6bf3497cb4eb5cc1717b3e31f3a48c562f51bf2/_is-num.scssc: can't dump anonymous class #<Class:0x007fe009798f88>
   Warning. Error encountered while saving cache d6bf3497cb4eb5cc1717b3e31f3a48c562f51bf2/_linear-angle-parser.scssc: can't dump anonymous class #<Class:0x007fe009798f88>
   ....

I'm using sass-rails (5.0.0.beta1) as it is added to the Gemfile by default with Rails 4.2 beta.
What can be going wrong?

Thanks in advance :)

@rafaelfranca
Copy link
Member

Can you please provide a sample application that reproduces the error?

@bigardone
Copy link
Author

Of course, here you are
https://github.com/bigardone/rails_and_react

Hope it helps

@daniel-rikowski
Copy link

The problem is the file system importer, it is not serializable using Marshal.dump, because the context is an anonymous class. (created by Class.new(Context))

Related: sass/sass#1372

Importers need to be serializable since sass 3.3 (https://github.com/sass/sass/blob/adc12b9a360f62871d7ec115a3f0d62309da32c5/lib/sass/importers/base.rb#L17)

Looks like this will be hard to fix. Perhaps providing custom marshal_dump/marshal_load methods could help...

@csuhta
Copy link

csuhta commented Sep 19, 2014

I have a workaround. I have no idea if I broke sourcemaps by doing this, I just wanted the warnings to stop because they were slowing down Sass considerably.

# config/initializers/shut_up_sass.rb
module Sass
  module Rails
    class SassImporter < Sass::Importers::Filesystem
      def marshal_dump
        # Return some kind of unique fingerprint to Sass
        @_marshal_id ||= object_id.to_s(16)
      end
      def marshal_load(*args)
        # Do nothing, we don't actually care if this is Marshalable
      end
    end
  end
end

@draknor
Copy link

draknor commented Oct 3, 2014

@csuhta - monkey patch works for me (in dev)! Thanks! Hope this gets fixed for real!

@robin850
Copy link
Member

robin850 commented Nov 9, 2014

(just for the record, this problem also occurs with sass-rails 4.0.3 apparently (c.f. #243))

@jakemauer
Copy link

Just wanted to chime in and say I have this issue when running locally as well.

Rails 4.2 beta
Sass-rails 5.0.0beta1

@KelseyDH
Copy link

I'm having the same issue after upgrading to Rails 3.2.21 from Rails 3.1.12. Relevant Gemfile.lock:

sass (3.4.8)
sass-rails (3.2.6)
  railties (~> 3.2.0)
  sass (>= 3.1.10)
sprockets (2.2.3)

In Heroku I get output like this:

       Running: rake assets:precompile
       Connecting to database specified by DATABASE_URL
       Compiled jquery-1.7.2.min.js  (1ms)  (pid 1139)
       Compiled jquery-ui.js  (5ms)  (pid 1139)
       Compiled jquery_ujs.js  (0ms)  (pid 1139)
       Compiled jquery.scrollto.min.js  (0ms)  (pid 1139)
       Compiled dataTables/jquery.dataTables.js  (6ms)  (pid 1139)
       Compiled dataTables/bootstrap/2/jquery.dataTables.bootstrap.js  (0ms)  (pid 1139)
       Compiled json2.js  (0ms)  (pid 1139)
       Compiled jquery.history.js  (0ms)  (pid 1139)
       Compiled jquery_nested_form.js  (0ms)  (pid 1139)
       Compiled ajaxify-html5.js  (0ms)  (pid 1139)
       Compiled bootstrap.js  (0ms)  (pid 1139)
       Compiled chosen.jquery.min.js  (0ms)  (pid 1139)
       Compiled clinic.js  (0ms)  (pid 1139)
       Compiled css3-mediaqueries.js  (0ms)  (pid 1139)
       Compiled highcharts.js  (43ms)  (pid 1139)
       Compiled jquery-ujs.js  (0ms)  (pid 1139)
       Compiled jquery.livesearch.js  (0ms)  (pid 1139)
       Compiled jquery.metadata.js  (0ms)  (pid 1139)
       Compiled jquery.tablesorter.js  (0ms)  (pid 1139)
       Compiled livesearch_implementation.js  (0ms)  (pid 1139)
       Compiled offices.js  (0ms)  (pid 1139)
       Compiled procedure.js  (0ms)  (pid 1139)
       Compiled referral_form.js  (0ms)  (pid 1139)
       Compiled resources.js  (223ms)  (pid 1139)
       Compiled review_items.js  (0ms)  (pid 1139)
       Compiled tablesorter_custom_parsers.js  (0ms)  (pid 1139)
       Compiled application.js  (391ms)  (pid 1139)
       Compiled all/normalize.css  (0ms)  (pid 1139)
       Compiled all/bootstrap.css  (1ms)  (pid 1139)
       Warning. Error encountered while saving cache /tmp/build_021d2e55d204a5978c62b78880e53182/tmp/cache/sass/490443b0b8710bda08f6b14e5d59a0bbac42b859/font-awesome.css.scssc: can't dump anonymous class #<Class:0x007f6bcbb32a48>
       Compiled all/font-awesome.css  (88ms)  (pid 1139)
       Warning. Error encountered while saving cache /tmp/build_021d2e55d204a5978c62b78880e53182/tmp/cache/sass/490443b0b8710bda08f6b14e5d59a0bbac42b859/bootstrap.modifications.css.scssc: can't dump anonymous class #<Class:0x007f6bcbb32a48>
       Warning. Error encountered while saving cache /tmp/build_021d2e55d204a5978c62b78880e53182/tmp/cache/sass/6cf1763d5d709cad34ac9be7a370f900ecc16302/_globals.css.scssc: can't dump anonymous class #<Class:0x007f6bcbb32a48>
       Compiled all/bootstrap.modifications.css  (119ms)  (pid 1139)
       Warning. Error encountered while saving cache /tmp/build_021d2e55d204a5978c62b78880e53182/tmp/cache/sass/490443b0b8710bda08f6b14e5d59a0bbac42b859/icons.css.scssc: can't dump anonymous class #<Class:0x007f6bcbb32a48>
       Warning. Error encountered while saving cache /tmp/build_021d2e55d204a5978c62b78880e53182/tmp/cache/sass/6cf1763d5d709cad34ac9be7a370f900ecc16302/_globals.css.scssc: can't dump anonymous class #<Class:0x007f6bcbb32a48>
       Compiled all/icons.css  (46ms)  (pid 1139)
      . . .

@rafaelfranca
Copy link
Member

Fixed on 4.0.5

@daniel-rikowski
Copy link

Is this really fixed on "4.0.5"?

I want to test it, but sass-rails 4.0.5 requires sass ~> 3.2.2 where the problem never existed in the first place.

@doryphores
Copy link
Contributor

I agree. @rafaelfranca Can you point to the commit that fixed this?

@KelseyDH
Copy link

KelseyDH commented Dec 4, 2014

Likewise. I can't upgrade to sass-rails 4.0.5 to fix this issue when moving to Rails 3.2.21 because that version of rails uses an earlier version of railsties:

Bundler could not find compatible versions for gem "railties":
  In Gemfile:
    sass-rails (~> 4.0.5) ruby depends on
      railties (< 5.0, >= 4.0.0) ruby
    rails (= 3.2.21) ruby depends on
      railties (3.2.21)

Is it possible to issue this patch to earlier versions of sass-rails so that people do not face this issues when trying to upgrade to Rails 4? We're anticipate lot of issues with people moving to Rails 4 if they encounter this issue with sass-rails when upgrading to Rails 3.2.x.

@matthewd
Copy link
Member

matthewd commented Dec 4, 2014

@KelseyDH Rails 3.2 is not supported.

I can only suggest you use a more consistent set of versions: if you're using a relatively ancient rails, you probably want correspondingly-old versions of sass, sass-rails, sprockets, etc.

@KelseyDH
Copy link

KelseyDH commented Dec 4, 2014

Thanks for responding. For Rails3.2.x can you point to a stable combination of these gem sets? Reading through issues this problem appears to have come and gone through various versions of sass, sprockets, and sass-rails. Finding the right combination of correspondingly-old sass-rails & sprockets versions to avoid this issue has proven difficult. When I follow Upgrade Guides using the recommended sass-rails versions this breaks. Upgrading to Rails3.2.17 (official recommended), Rails3.2.18 (edge upgrade recommended) & Rails3.2.21(latest release) all produce this issue.

I understand you do not support older sass-rails versions; but having a cogent path for Rails3.1.x apps to upgrade sass-rails with sprockets is a necessity if apps with production requirements are going to have hope of keeping up-to-date with new versions. (This 'relatively ancient' app only went into production 3 years ago... to have this type of instability so soon is exactly what causes enterprise environments to get spooked away from Rails).

If I or another person finds the right combination of safe versions I'll post it. Updating the rails upgrade guides with the new gemsets would be a good idea. For posterity here are relevant sections of my Gemfile.lock involving sprockets, railties, sass, sass-rails and dalli after upgrading to Rails 3.2.17 that generates the "can't dump anonymous class" issue when pushed to heroku:


GEM
  remote: https://rubygems.org/
  specs:
    actionpack (3.2.17)
      sprockets (~> 2.2.1)
    coffee-rails (3.2.2)
      coffee-script (>= 2.2.0)
      railties (~> 3.2.0)

    dalli (2.7.2)

    jquery-datatables-rails (3.0.0)
      jquery-rails
      sass-rails
    jquery-rails (1.0.19)
      railties (~> 3.0)
      thor (~> 0.14)
    rails (3.2.17)
      railties (= 3.2.17)

    railties (3.2.17)
      actionpack (= 3.2.17)
      activesupport (= 3.2.17)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.14.6, < 2.0)

    sass (3.4.9)
    sass-rails (3.2.6)
      railties (~> 3.2.0)
      sass (>= 3.1.10)


    sprockets (2.2.3)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)

@matthewd
Copy link
Member

matthewd commented Dec 7, 2014

went into production 3 years ago... to have this type of instability so soon is exactly what causes enterprise environments to get spooked away from Rails

Firstly: if the published Maintenance Policy is unacceptable to anyone, "enterprise environment" or otherwise, they should generally either 1) use something else, 2) pay someone to provide extended support, or 3) accept the risks, and wear the consequences, of deliberately running unsupported software. An implication of "we/others may use something else instead" fundamentally misapprehends the nature of a freely provided open source project.

Despite the above, I'll go ahead and re-answer your question:

you probably want correspondingly-old versions of 💁 👉 ✨ sass ✨ 👈, sass-rails, sprockets, etc.

(subtle emphasis added)

I can't give you an exact set of versions, but I would expect you to have better luck if you use the latest available point-release of the release series that was current when Rails 3.2.0 was released, instead of a week-old release of a series that didn't exist until several months after Rails 3.2 became unsupported. Versions newer than that may work, or may not.

I'll separately look into a suitable change to the upgrade guide... I'm not sure why we'd still [attempt to] document that at all.

@KelseyDH
Copy link

KelseyDH commented Dec 9, 2014

@matthewd Thank you for replying.

I applied your advice, it's now working! As you recommended I updated my gemfile to specify the sass gem to one more compatible with the Rails 3.2.x era:

gem 'rails', '3.2.21'

group :assets do
  gem 'sass', '~> 3.1.10'
  gem 'sass-rails',   '~> 3.2.6'
  gem 'coffee-rails', '~> 3.2.2'
  gem 'uglifier',     '>= 1.0.3'
end

With this changed Gemfile I ran bundle update 'sass' and it worked.

The can't dump anonymous class issue was resolved by specifying sass in the top of my Gemfile to a lower version compatible with Rails 3.2.x (sass (3.2.10)). The problem appears to be that even though sass-rails specifies 3.2.6, the sass gem automatically updates to a breaking version when rails 3.1.x is updated to rails 3.2.x (installing sass as sass (3.4.9)).

It might be a good idea in the Rails 3.2.x upgrade guides to specify gem 'sass', '~> 3.1.10' above gem 'sass-rails', '~> 3.2.6' to prevent this issue. Or alternatively, to specify that sass-rails load a gem version of sass lower than 3.2 to prevent this issue (sass-rails 3.2.6 currently only specifies needing sass versions higher than sass 3.1.0, appearing to allow sass-rails to include sass versions above 3.2.0 that breaks if upgrading to rails 3.2.x,).

The second option, of specifying sass versions properly within sass-rails is arguably better if possible, as it would make the next step of upgrading to rails 4.x less time consuming for people as they do not need to readdress the issue of sass versions in their gemfile.

PS: I understand the difficulties of maintaining open source projects in older versions -- I am only relaying a sentiment that other developers give me about trusting Rails for future projects when they hear about these issues. Where I can I will make my own contributions where I can. I appreciate immensely the (unpaid) time maintainers such as yourself give to our issues.

@daniel-rikowski
Copy link

@KelseyDH I'm glad you found a working solution.

The problem appears to be that even though sass-rails specifies 3.2.6, the sass gem automatically updates to a breaking version when rails 3.1.x is updated to rails 3.2.x

That is because the old sass-rails gem only specified a minimum version of sass. You were probably looking at the source of the current version. If you look at the source of the old version, you can find the older and less restrictive dependency (https://github.com/rails/sass-rails/releases/tag/v3.2.6) By using an older version of sass-rails you always got the latest version of sass.

I am only relaying a sentiment that other developers give me about trusting Rails for future projects

I understand your frustration, but that is just FUD. Your problem was - as @matthewd said and you just verified - a dependency problem. Name one enterprise framework which hadn't had those. (Maven anyone?)

@daniel-rikowski
Copy link

It looks like it is really fixed now. I tested Rails 4.2.0.rc2 using the master branch of sass-rails and it works.

Looks like #292 did the job. 👍

nisanthchunduru added a commit to nisanthchunduru/sass-rails that referenced this issue Jun 4, 2017
Fixes this caching error

  Warning. Error encountered while saving cache /Users/nisanth/code/MyRailsProject/tmp/cache/sass/72de6cc44bbce063300f964c05a1a5e4c7dbb433/base.scssc: can't dump anonymous class #<Class:0x007fedd01a6858>

See rails#242 and rails#292 for more details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants