Coder Social home page Coder Social logo

Comments (28)

hugocorbucci avatar hugocorbucci commented on August 13, 2024

👍
Finding the same problem. App works fine with konacha 3.7.0 and sprockets 2.3.
Works fine with sprockets 3.0 without Konacha.
Won't work with both. Same error

from konacha.

hugocorbucci avatar hugocorbucci commented on August 13, 2024

Quick debugging session here pointed to the fact that in engine.rb:14, app.assets is nil.
Haven't figured out what is was supposed to be yet.

from konacha.

hugocorbucci avatar hugocorbucci commented on August 13, 2024

And some more pointed to the new sprockets-rails code that only assigns app.assets if config.assets.compile is set and also only does that on after_initialize.

Also just as an answer to myself: app.assets is supposed to be a Sprockets::Environment instance.

from konacha.

afn avatar afn commented on August 13, 2024

And some more pointed to the new sprockets-rails code that only assigns app.assets if config.assets.compile is set and also only does that on after_initialize.

Also just as an answer to myself: app.assets is supposed to be a Sprockets::Environment instance.

See https://github.com/rails/sprockets-rails#initializer-options — you should now use config.assets.configure with a block, rather than calling app.assets directly. E.g. instead of app.assets.register_engine, you would do:

app.config.assets.configure do |env|
  env.register_engine ...
end

I know that doesn't quite solve the problem but hopefully that sheds a bit of light...

from konacha.

alexkravets avatar alexkravets commented on August 13, 2024

+1

from konacha.

dirkdk avatar dirkdk commented on August 13, 2024

+1

from konacha.

stevenchanin avatar stevenchanin commented on August 13, 2024

The particular commit on sprockets-rails that causes konacha tests to start failing (e.g. bundle exec rake in in git clone of konacha begins to fail after this point) is:
rails/sprockets-rails@d7c7ee1

Since the description for that commit is "Rails.application.assets is nil when compile=false" it makes sense that it is causing the problems we're all seeing.

I have a fork of Konacha (https://github.com/stevenchanin/konacha) with a Gemfile that has the specific refs for the two adjacent commits to rails-sprockets that make Konacha flip from working to breaking.

If you edit ./konacha/lib/konacha/engine.rb:14 and change run app.assets to run app.config.assets the crashes go away, but then you start getting errors like:

Asset was not declared to be precompiled in production.
Add `Rails.application.config.assets.precompile += %w( konacha.css )` to `config/initializers/assets.rb` and restart your server

I hope this helps correct the issue.

from konacha.

afn avatar afn commented on August 13, 2024

@stevenchanin Thanks for chipping in! Unfortunately, I don't think this is a viable solution; if I read it correctly, your solution is to depend on an older version of sprockets. The issue at hand, though, is that Sprockets 3.0 introduced a breaking change (not a bug) starting with the commit that you identified, and Konacha needs to be updated to deal with the change.

from konacha.

stevenchanin avatar stevenchanin commented on August 13, 2024

@afn - I agree. I think Konacha needs to become compatible with the current sprockets version to be workable. I also agree that the change to app.config.assets isn't a fix (it doesn't work...). I was just trying to provide the info I was able to figure out in the hope that it would enable someone who understands Konacha / rails engines better to make a real fix.

from konacha.

alexkravets avatar alexkravets commented on August 13, 2024

@stevenchanin @afn @dirkdk could you please check if this works for you: https://github.com/alexkravets/konacha — this fixed the problem for me, but we don't have lot of tests as of now. Will have to fix tests as well.

Please run in test environment: RAILS_ENV=test rake konacha:run

from konacha.

stevenchanin avatar stevenchanin commented on August 13, 2024

@alexkravets - when I try your fork, I get mixed results. Executing the tests from the command line as you suggest (RAILS_ENV=test rake konacha:run) seems to work. I see green dots.

However, if I try to run them either from the command line without explicitly setting RAILS_ENV (bundle exec rake konacha:run), I get:

ActionView::Template::Error: Asset was not declared to be precompiled in production.
Add `Rails.application.config.assets.precompile += %w( konacha.css )` to `config/initializers/assets.rb` and restart your server
    /Users/Steven/.rvm/gems/ruby-2.3.0@marketplace/gems/sprockets-rails-3.0.0/lib/sprockets/rails/helper.rb:350:in `raise_unless_precompiled_asset'

If I try to run the konacha server (bundle exec rake konacha:serve), it starts up fine, but when I hit localhost:3500, I it crashes with a similar error:

* Listening on tcp://localhost:3500
ActionView::Template::Error: Asset was not declared to be precompiled in production.
Add `Rails.application.config.assets.precompile += %w( konacha.css )` to `config/initializers/assets.rb` and restart your server
    /Users/Steven/.rvm/gems/ruby-2.3.0@marketplace/gems/sprockets-rails-3.0.0/lib/sprockets/rails/helper.rb:350:in `raise_unless_precompiled_asset'

However, if I include RAILS_ENV=test at the beginning of of the server startup command:

RAILS_ENV=test bundle exec rake konacha:serve

then the server runs correctly without problems.

Does that give you any clues?

from konacha.

alexkravets avatar alexkravets commented on August 13, 2024

Yes, so a few moments that were fixed in the fork:

  1. Due to the changes in sprockets config.assets object is not initialized, so Sprockets::Environment created manually here:
    alexkravets@5407404#diff-eedb8e320ca29178c5560af0eca453d2R11
  2. In latest sprockets raise_runtime_errors is not supported anymore, that's why these precompile errors happen. To fix it workaround is added:
    alexkravets@5407404#diff-eedb8e320ca29178c5560af0eca453d2R58

This fix removes precompile notifications in test environment. This seems to be fine as those are not really used there.

But when you run tests in development environment this workaround doesn't applied so you see these errors. We can change replace Rails.env.test? with Rails.env.development? — but that will break default Rails behavior.

from konacha.

alexkravets avatar alexkravets commented on August 13, 2024

Here is a discussion around the issue: rails/sprockets-rails#299

from konacha.

edwardloveall avatar edwardloveall commented on August 13, 2024

@alexkravets your branch worked for me (albeit with a very simple test suite) using RAILS_ENV=test rake konacha:run

from konacha.

hugocorbucci avatar hugocorbucci commented on August 13, 2024

@alexkravets I get the same as @stevenchanin for my projects.
Not sure I understand why the || Rails.env.test? at alexkravets@5407404#diff-eedb8e320ca29178c5560af0eca453d2R59

I get the effect of it (say we have that file just fine if we're running konacha tests) but wouldn't it be better to be something like || konacha_checker[logical_path] and just consider the files konacha does provide as being present? And in that case it doesn't matter if we're in test environment but rather only that Konacha is loaded (assuming konacha is in the development/test group in Gemfile or required only when needed)?

from konacha.

alexkravets avatar alexkravets commented on August 13, 2024

@hugocorbucci great idea! Will work on that.

from konacha.

hugocorbucci avatar hugocorbucci commented on August 13, 2024

Sorry @alexkravets. By no means was I trying to give you more work. I was just trying to understand the solution :)
If you're not too deep in it already, I can give it a shot tomorrow evening...

from konacha.

alexkravets avatar alexkravets commented on August 13, 2024

@hugocorbucci absolutely, no problem. I've not started yet.

from konacha.

stevenchanin avatar stevenchanin commented on August 13, 2024

@alexkravets - Thanks very much for the work so far. We're testing a branch of our project now that uses your fork & that allows us to bump up Rails versions and others. So far, it looks good.

from konacha.

alexkravets avatar alexkravets commented on August 13, 2024

@hugocorbucci @stevenchanin please check this out: alexkravets@f049dcf — latest commit removes test environment requirement, so all rspec tests do pass now. Thanks @hugocorbucci for the idea!

Please check if everything works on your end and if there are no issues, I'll make a pull request.

from konacha.

edwardloveall avatar edwardloveall commented on August 13, 2024

This just worked for me! Before this, I had to add all my assets manually to Rails.application.config.assets.precompile. This branch fixes that. Thanks!

from konacha.

tomhughes avatar tomhughes commented on August 13, 2024

I can confirm that the OpenStreetMap code works fine with your patches applied.

One thing to beware of is that with that applied you must use the newer sprockets-rails, so the gemspec will need updating to reflect that.

from konacha.

alexkravets avatar alexkravets commented on August 13, 2024

@tomhughes thanks, fixed!

from konacha.

stevenchanin avatar stevenchanin commented on August 13, 2024

@alexkravets Just tried the newest version (e2c6f85) and it worked perfectly for me without having to specify the environment. Nice work!

from konacha.

dirkdk avatar dirkdk commented on August 13, 2024

thank you guys!

from konacha.

hugocorbucci avatar hugocorbucci commented on August 13, 2024

@alexkravets Yep! Solved all my projects too. Great job! Thanks a lot

@jfirebaugh Any chance if @alexkravets issues a PR that we'll get a new version in rubygems?

from konacha.

jfirebaugh avatar jfirebaugh commented on August 13, 2024

I'm happy to accept a PR that adds compatibility for sprockets 3.0, subject to the following backward compatibility constraints:

  • I want to continue supporting Rails >= 4.1
  • I want to continue supporting the minimum version of sprockets supported by Rails 4.1 (not sure what the Rails ⨯ Sprockets support matrix looks like)
  • I would accept dropping support for Rails < 4.1 if necessary
    • If so, this will be a major version change

from konacha.

jfirebaugh avatar jfirebaugh commented on August 13, 2024

Fixed in 71b47cc and 857dd37 and will be released in 4.0 shortly. Thanks everyone!

from konacha.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.