emberjs / ember-rails

Ember for Rails 3.1+
https://github.com/emberjs/ember-rails
MIT License
1.36k stars 252 forks source link

Sprockets 3.0 issues #469

Closed kirs closed 9 years ago

kirs commented 9 years ago

We enabled tests under Sprockets 3.0 here, but it still fails:

/Users/kir/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/ember-rails-0.18.2/lib/ember_rails.rb:55:in `block in <class:Railtie>': undefined method `append_path' for nil:NilClass (NoMethodError)
    from /Users/kir/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/kir/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
    from /Users/kir/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/kir/.rbenv/versions/2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /Users/kir/.rbenv/versions/2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'

Here is the demo app: https://github.com/kirs/ember-sprockets-3 (type rake to reproduce the issue`)

kirs commented 9 years ago

/cc @tricknotes

tricknotes commented 9 years ago

It seems sprockets-rails issue for me.

sprockets-rails version working?
2.2.4 o
3.0.0.beta.1 o
master x

I'll check about more detail in this weekend.

tricknotes commented 9 years ago
sprockets-rails version working?
2.2.4 o
3.0.0.beta.1 o
master x

Note: All of them are tested with sprockets 3.0.0.

tricknotes commented 9 years ago

Ar right. Probably you mean the same fix as https://github.com/reactjs/react-rails/pull/241 is required in ember-rails too.

kirs commented 9 years ago

Thanks for the fast reply! Let me try 3.0.0.beta.1

Actually the fix I sent to react-rails doesn't work with test env: https://github.com/reactjs/react-rails/pull/241#issuecomment-92715133

kirs commented 9 years ago

This is weird, but I see that 3.0.0.beta.1 actually depends on Sprockets 2.x: https://rubygems.org/gems/sprockets-rails/versions/3.0.0.beta1

kirs commented 9 years ago

https://github.com/rails/sprockets-rails/commit/40cd1d4c1966e8920242a8786f834e425ecacbbb#commitcomment-8120382

kirs commented 9 years ago

@josh any thoughts?

josh commented 9 years ago

I haven't see the code, but I have a pretty good bet I know whats wrong.

You only want to touch Rails.application.assets inside a configure block if you using an initializer. Otherwise it depends on the unpredictable order that someones initializers end up running in.

config.assets.configure do |env|
  env.append_path ...
  env.register_processor ..
end

If you just touching paths, I think you can just modify config.assets.paths <<. That may have slightly different semantics. But the configure block suggestion should work the same. Its totally backwards compatible since the plugin existed. It was mostly a bug that the old code path seemly worked sometimes.

Hope that helps, feel free to @mention on the proposed PR.

justqyx commented 9 years ago

I have met the same problem too.

The Ember::Handlebars::Template processor has added to the engines of sprockets successfully.

Rails.application.assets.engines
=> {".coffee"=>Sprockets::CoffeeScriptProcessor,
 ".jst"=>Sprockets::JstProcessor,
 ".eco"=>Sprockets::EcoProcessor,
 ".ejs"=>Sprockets::EjsProcessor,
 ".sass"=>Sass::Rails::SassTemplate,
 ".scss"=>Sass::Rails::ScssTemplate,
 ".erb"=>Sprockets::ERBProcessor,
 ".handlebars"=>Ember::Handlebars::Template,
 ".hbs"=>Ember::Handlebars::Template,
 ".hjs"=>Ember::Handlebars::Template}

but when I try to find_asset

=> {:dependencies=>
  #<Set: {"environment-version",
   "environment-paths",
   "processors:type=application/javascript&file_type=application/javascript",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/learning.js",
   "processors:type=application/javascript&file_type=application/javascript&pipeline=self",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/adapters.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/mixins.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/custom_model.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/controllers/courses/index_controller.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/controllers/courses/learn_controller.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/controllers/courses/show_controller.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/helpers.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components/chapter-sidebar_component.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components/display-comic_component.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components/display-courseware_component.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components/display-exercise_component.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components/display-game_component.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components/display-quiz_component.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components/display-video_component.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components/display-web_component.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components/section-sidebar_component.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/routes/courses/index_route.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/routes/courses/learn_route.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/routes/courses/show_route.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/routes/index_route.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/initializers.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/router.js",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/adapters",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/mixins",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/custom_model",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/controllers",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/controllers/courses",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/helpers",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/components",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/templates",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/templates/components",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/templates/courses",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/routes",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/routes/courses",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/initializers",
   "file-digest:///Users/star/code/neolion_backend/app/assets/javascripts/learning/router"}>,

we can see the handlebars template were ignored.

app/assets/javascripts/learning/templates
├── components
│   ├── chapter-sidebar.hbs
│   ├── display-comic.hbs
│   ├── display-courseware.hbs
│   ├── display-exercise.hbs
│   ├── display-game.hbs
│   ├── display-quiz.hbs
│   ├── display-video.hbs
│   ├── display-web.hbs
│   └── section-sidebar.hbs
└── courses
    ├── index.hbs
    ├── learn.hbs
    └── show.hbs

env

sprockets '~> 3.0.1'
sprockets-rails '~> 2.2.4'

@josh How could I fix this ?

justqyx commented 9 years ago

I fix it by adding this code in config/application.rb

config.assets.configure do |env|
  env.register_engine '.hbs', Ember::Handlebars::Template, mime_type: 'application/javascript'
end
matthooks commented 9 years ago

I was running into an issue where handlebars templates weren't rendering at all using sprockets 3.1.0, sprockets-rails 2.3.1, ember-rails 0.18.2, and ember-handlebars-template 0.2.0 and was able to fix it using @justqyx's suggestion.

Seems like the engine is being registered at the wrong level?

tricknotes commented 9 years ago

I think this is fixed by https://github.com/emberjs/ember-rails/pull/495 . If not fixed yet, please reopen this issue.