LoginSignup
11
5

More than 3 years have passed since last update.

circleciでrspecを実行すると、Webpacker can't find applicationのエラーが出た

Last updated at Posted at 2020-07-09

ローカルでは通っていたテストがcircleciで実行すると、Webpacker can't find applicationのエラーが出て、解決できたのでメモとして記録

参考URL

rspecのエラー全文

Failure/Error: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

       ActionView::Template::Error:
         Webpacker can't find application in /home/circleci/sample_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:
         {
         }

原因

circleciの環境の中でyarnが必要にも関わらずインストールをせずに、- run: bundle exec bin/webpackでビルドしようとしていたから、エラーが発生していた

.circleci/config.yalの中身(エラー発生時)

version: 2.1
orbs:
  ruby: circleci/ruby@0.1.2

jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/ruby:2.5.3-stretch-node
        environment:
          - RAILS_ENV: 'test'
      - image: circleci/mysql:8.0
        name: "db"
        command: mysqld --default-authentication-plugin=mysql_native_password
        environment:
          - MYSQL_ROOT_PASSWORD: password

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/postgres:9.4

    working_directory: ~/sample_app

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "Gemfile.lock" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: bundle install --jobs=4 --retry=3 --path vendor/bundle
      - save_cache:
          paths:
            - ./vendor/bundle
          key: v1-dependencies-{{ checksum "Gemfile.lock" }}

      # Database setup
      - run: bundle exec rake db:create
      - run: bundle exec rake db:schema:load

      - run: bundle exec bin/webpack

# rspec
      # run tests!
      - run:
          name: run tests
          command: |

            mkdir -p /tmp/test-results
            TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
              circleci tests split --split-by=timings)"


            bundle exec rspec \
              --format progress \
              --format RspecJunitFormatter \
              --out /tmp/test-results/rspec.xml \
              --format progress \
              $TEST_FILES

      # collect reports
      - store_test_results:
          path: /tmp/test-results
      - store_artifacts:
          path: /tmp/test-results
          destination: test-results

解決方法

先にyarnをインストールしてから、実行してやるとエラーは消えた

 +    - run:
 +        name: yarn Install
 +        command: yarn install
      - run: bundle exec bin/webpack

反省

全般的にやけど、理解もせずに使ってしまっているからエラーの解決に苦戦してしまう。

11
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
5