🖥

Rails6 – rspec + capybara のテストで Webpacker::Manifest::MissingEntryError

に公開

問題

rspecでページにvisitするだけでエラーが発生する

require 'rails_helper'

feature type: :feature do
  scenario do
    visit new_user_session_path
  end
end

エラー

Failures:

  1) {:type=>:feature}
     Failure/Error: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

     ActionView::Template::Error:
       Webpacker can't find application.js in /Users/yumainaura/projects/YumaInaura/rails6-app/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:
       {
       }
     # ./app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb__639505929452759243_23340'
     # ./spec/features/login_spec.rb:5:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # Webpacker::Manifest::MissingEntryError:
     #   Webpacker can't find application.js in /Users/yumainaura/projects/YumaInaura/rails6-app/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:
     #   {
     #   }
     #   ./app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb__639505929452759243_23340'

Finished in 6.57 seconds (files took 4.64 seconds to load)
1 example, 1 failure

解決?

webpacker.yaml の test の設定を development に合わせてみたら成功するようになった

以下はデフォルトの設定

test:
  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

developmentと全く同じ設定にしたもの


test:
  <<: *default
  compile: true

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    pretty: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: '**/node_modules/**'

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2023-01-07

Discussion