Comments (28)
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.
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.
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.
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.
+1
from konacha.
+1
from konacha.
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.
@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.
@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.
@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.
@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.
Yes, so a few moments that were fixed in the fork:
- Due to the changes in sprockets
config.assets
object is not initialized, so Sprockets::Environment created manually here:
alexkravets@5407404#diff-eedb8e320ca29178c5560af0eca453d2R11 - 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.
Here is a discussion around the issue: rails/sprockets-rails#299
from konacha.
@alexkravets your branch worked for me (albeit with a very simple test suite) using RAILS_ENV=test rake konacha:run
from konacha.
@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.
@hugocorbucci great idea! Will work on that.
from konacha.
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.
@hugocorbucci absolutely, no problem. I've not started yet.
from konacha.
@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.
@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.
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.
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.
@tomhughes thanks, fixed!
from konacha.
@alexkravets Just tried the newest version (e2c6f85) and it worked perfectly for me without having to specify the environment. Nice work!
from konacha.
thank you guys!
from konacha.
@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.
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.
Fixed in 71b47cc and 857dd37 and will be released in 4.0 shortly. Thanks everyone!
from konacha.
Related Issues (20)
- undefined method `each_entry' for #<Sprockets::Environment:0x007fb129769378> HOT 11
- Tests failing due to Load Error HOT 1
- Unable to run Konacha in headless mode HOT 5
- How do I use Konacha when testing gemified javascript HOT 2
- undefined method `generate_key' for nil:NilClass HOT 1
- Do you have any update/success with use some coverage formatter, like `istanbul`? HOT 1
- Setting a dynamic host HOT 2
- 'spec_dir' is a slightly misleading term because we can actually specify multiple directories.
- Require commonjs module, e.g. export.default HOT 1
- Using Konacha with poltergeist Missing Template Error
- Add an easy way to bind konacha server to 0.0.0.0 HOT 3
- Firefox 47 with selenium marionette driver fails
- Grep Path incorrect. HOT 1
- Rails 5 support HOT 6
- Rack application timed out during boot HOT 1
- Konacha:serve works but get error attempting to use the runner
- NoMethodError when using DocumentationFormatter and capybara_webkit
- Mocha v3.0.0 support
- Incompatible with colored gem
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from konacha.