rails / webpacker

Use Webpack to manage app-like JavaScript modules in Rails
MIT License
5.3k stars 1.47k forks source link

Webpacker 3.0 doesn't build CSS for Rails system tests #733

Closed alex-kovshovik closed 7 years ago

alex-kovshovik commented 7 years ago

Brand new Rails 5.1.3 app with just this problem repeated: https://github.com/alex-kovshovik/webpacker30-test

I created the application.sass file under app/javascript/sass and then added the following to my app/javascript/packs/application.js:

require("../sass/application.sass");

webpack-test - rubymine 2017 2 3 eap 2017-08-31 20-07-16

This works great in development: SASS file is compiled into CSS and is put into public/packs.

When I try to run a Rails system tests (bin/rails test:system) - it fails with the following error:

Puma starting in single mode...
* Version 3.10.0 (ruby 2.4.1-p111), codename: Russell's Teapot
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:64747
Use Ctrl-C to stop
2017-08-31 20:03:19 -0400: Rack app error handling request { GET / }
#<ActionView::Template::Error: Webpacker can't find application.css in /Users/alexk/dev/webpack-test/public/packs-test/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
   unless you are using the `webpack -w` or the webpack-dev-server.
2. Webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your Webpack configuration is not creating a manifest.
Your manifest contains:
{
  "application.js": "/packs-test/application-81a4ebcfe2d4b25684bc.js"
}
>
/Users/alexk/.rvm/gems/ruby-2.4.1/bundler/gems/webpacker-5d45278e99d2/lib/webpacker/manifest.rb:44:in `handle_missing_entry'
/Users/alexk/.rvm/gems/ruby-2.4.1/bundler/gems/webpacker-5d45278e99d2/lib/webpacker/manifest.rb:40:in `find'
/Users/alexk/.rvm/gems/ruby-2.4.1/bundler/gems/webpacker-5d45278e99d2/lib/webpacker/manifest.rb:27:in `lookup'
/Users/alexk/.rvm/gems/ruby-2.4.1/bundler/gems/webpacker-5d45278e99d2/lib/webpacker/helper.rb:59:in `block in sources_from_pack_manifest'
/Users/alexk/.rvm/gems/ruby-2.4.1/bundler/gems/webpacker-5d45278e99d2/lib/webpacker/helper.rb:59:in `map'
/Users/alexk/.rvm/gems/ruby-2.4.1/bundler/gems/webpacker-5d45278e99d2/lib/webpacker/helper.rb:59:in `sources_from_pack_manifest'
/Users/alexk/.rvm/gems/ruby-2.4.1/bundler/gems/webpacker-5d45278e99d2/lib/webpacker/helper.rb:53:in `stylesheet_pack_tag'
/Users/alexk/dev/webpack-test/app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__3174900383150293565_70351628999780'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/template.rb:157:in `block in render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/notifications.rb:168:in `instrument'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/template.rb:352:in `instrument_render_template'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/template.rb:155:in `render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/renderer/template_renderer.rb:64:in `render_with_layout'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/renderer/template_renderer.rb:50:in `render_template'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/renderer/template_renderer.rb:14:in `render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/renderer/renderer.rb:42:in `render_template'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/renderer/renderer.rb:23:in `render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/rendering.rb:103:in `_render_template'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/streaming.rb:217:in `_render_template'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/rendering.rb:83:in `render_to_body'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/rendering.rb:52:in `render_to_body'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/renderers.rb:141:in `render_to_body'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/abstract_controller/rendering.rb:24:in `render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/rendering.rb:36:in `render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/Users/alexk/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/core_ext/benchmark.rb:12:in `ms'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.3/lib/active_record/railties/controller_runtime.rb:29:in `cleanup_view_runtime'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/instrumentation.rb:43:in `render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/implicit_render.rb:33:in `default_render'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/basic_implicit_render.rb:4:in `block in send_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/basic_implicit_render.rb:4:in `tap'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/abstract_controller/base.rb:186:in `process_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/rendering.rb:30:in `process_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:131:in `run_callbacks'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/abstract_controller/callbacks.rb:19:in `process_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/rescue.rb:20:in `process_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/notifications.rb:166:in `block in instrument'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/notifications.rb:166:in `instrument'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.3/lib/active_record/railties/controller_runtime.rb:22:in `process_action'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/abstract_controller/base.rb:124:in `process'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionview-5.1.3/lib/action_view/rendering.rb:30:in `process'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal.rb:189:in `dispatch'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_controller/metal.rb:253:in `dispatch'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/routing/route_set.rb:31:in `serve'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/journey/router.rb:46:in `block in serve'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/journey/router.rb:33:in `each'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/journey/router.rb:33:in `serve'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/routing/route_set.rb:834:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/etag.rb:25:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/conditional_get.rb:25:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:232:in `context'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:226:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/middleware/cookies.rb:613:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:97:in `run_callbacks'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/middleware/callbacks.rb:24:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/rack/logger.rb:36:in `call_app'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/rack/logger.rb:24:in `block in call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/tagged_logging.rb:69:in `block in tagged'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/tagged_logging.rb:26:in `tagged'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/tagged_logging.rb:69:in `tagged'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/rack/logger.rb:24:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/middleware/request_id.rb:25:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/method_override.rb:22:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/runtime.rb:22:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/middleware/executor.rb:12:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/actionpack-5.1.3/lib/action_dispatch/middleware/static.rb:125:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/sendfile.rb:111:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/engine.rb:522:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/urlmap.rb:68:in `block in call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `each'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/rack-2.0.3/lib/rack/builder.rb:153:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/capybara-2.15.1/lib/capybara/server.rb:44:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/puma-3.10.0/lib/puma/configuration.rb:225:in `call'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/puma-3.10.0/lib/puma/server.rb:605:in `handle_request'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/puma-3.10.0/lib/puma/server.rb:437:in `process_client'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/puma-3.10.0/lib/puma/server.rb:301:in `block in run'
/Users/alexk/.rvm/gems/ruby-2.4.1/gems/puma-3.10.0/lib/puma/thread_pool.rb:120:in `block in spawn_thread'

I tried to find solutions online and reviewed other webpacker issues: couldn't figure it out. Please help, if that's OK :)

curvo commented 7 years ago

I cloned your repo and wasn't able to reproduce this. Is there something missing? Here are the steps I took:

  1. git clone
  2. bundle
  3. yarn

Then I ran the rails server to see the the packs working in dev mode. Then I ran your test command:

[BC]webpacker30-test $ bin/rails test:system
/Users/bcase/Code/OpenSource/Examples/webpacker30-test/db/schema.rb doesn't exist yet. Run `rails db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /Users/bcase/Code/OpenSource/Examples/webpacker30-test/config/application.rb to limit the frameworks that will be loaded.
Run options: --seed 39679

# Running:

Puma starting in single mode...
* Version 3.10.0 (ruby 2.3.3-p222), codename: Russell's Teapot
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:50203
Use Ctrl-C to stop
.

Finished in 5.092019s, 0.1964 runs/s, 0.1964 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

Am I missing something?

alex-kovshovik commented 7 years ago

Hm, this is strange: something must have been cached in my working copy. When I cloned my own repo into a different location - it worked too. Sorry for the false alarm.

I then created another brand new Rails app and it worked again. Here are the steps:

  1. rails new webpacker-test --webpack
  2. create route + controller + action + view
  3. create app/javascript/application.sass
  4. require it from app/javascript/packs/application.js
  5. add javascript_pack_tag and stylesheet_pack_tag to the layout template
  6. run bin/rails s to make sure styles from sass file are loaded
  7. create a simple system test and run it
  8. all works as expected
alex-kovshovik commented 7 years ago

In case this helps somebody else: in my working copy with the problem I had public/packs and public/packs-test directories. After I've deleted them and restarted system tests - it worked. Must have been some local dev caching issue.

To get webpacker to re-build everything:

  1. rm -rf public/packs
  2. rm -rf public/packs-test
jonesmac commented 7 years ago

I ran into a similar issue. My assets were not fully compiling when running tests giving me the same error as @alex-kovshovik . Then I ran RAILS_ENV=test bin/webpack to force compiling my assets under test and low and behold I didn't have the correct bindings for nodesass for my version of osx. Once I fixed that, all my assets compiled correctly. If there is an issue, it might be that when the compilation of the assets under TEST fails, it doesn't stop running the tests which is confusing. Thoughts?

jDeppen commented 4 years ago

Thanks, @jonesmac! npm rebuild node-sass fixed it for me