Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionView::Template::Error: Webpacker can't find application in /app/public/packs/manifest.json when its deploy to the Gitlab #2674

Closed
Sakshi1305 opened this issue Jul 30, 2020 · 10 comments

Comments

@Sakshi1305
Copy link

Sakshi1305 commented Jul 30, 2020

Hello, I know this is not a new issue and I've checked multiple sources to see if the solutions are helpful but it yields no positive outcome, it works perfect locally but receive this error during pipelines running with CI/CD in test stage when it's deployed to the Gitlab:

Webpacker::Manifest::MissingEntryError: Webpacker can't find application in /app/public/packs/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:
{
}

Here are few lines from the application.html file:

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

and my stylesheets are .scss files and there's no .css file in the project.

This is my webpacker.yml :

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_root_path: public
  public_output_path: packs
  cache_path: tmp/cache/webpacker
  check_yarn_integrity: false
  webpack_compile_output: true

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: [ ]

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  # Extract and emit a css file
  extract_css: true

  static_assets_extensions:
    - .jpg
    - .jpeg
    - .png
    - .gif
    - .tiff
    - .ico
    - .svg
    - .eot
    - .otf
    - .ttf
    - .woff
    - .woff2

  extensions:
    - .mjs
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

  # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
  check_yarn_integrity: 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/**"

test:
  <<: *default
  compile: true

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

production:
  <<: *default

  # Production depends on the precompilation of packs prior to booting for performance.
  compile: false

  # Extract and emit a css file
  extract_css: true

  # Cache manifest.json for performance
  cache_manifest: true

Am I missing anything?

@Sakshi1305 Sakshi1305 changed the title ActionView::Template::Error: Webpacker can't find application in /app/public/packs/manifest.json ActionView::Template::Error: Webpacker can't find application in /app/public/packs/manifest.json when its deploy to the Gitlab Jul 30, 2020
@rossta
Copy link
Member

rossta commented Aug 5, 2020

@Sakshi1305 Is this error happening in your tests? If so, does precompiling assets before the tests are run help, i.e.: RAILS_ENV=test bin/rake assets:precompile?

@Sakshi1305
Copy link
Author

@Sakshi1305 Is this error happening in your tests? If so, does precompiling assets before the tests are run help, i.e.: RAILS_ENV=test bin/rake assets:precompile?

Thanks @rossta but this also gave me the same error. I already tried this. This error happens during ci/cd autodevops pipeline on GitLab

@BlackRabbitt
Copy link

@Sakshi1305 This error happened to me as well when trying to run request spec in gitlab ci.
This can be fixed by rails webpacker:compile but to run this in gitlab-ci, you need to configure gitlab.ci.yml (basically to support node and yarn/npm)
Following is the snippet for my gitlab.ci.yml

.test_app:
  image: "ruby:2.6.5"
  cache:
    paths:
      - vendor/ruby
      - node_modules
  services:
    - postgres:latest
  variables:
    RAILS_ENV: test
    POSTGRES_HOST_AUTH_METHOD: trust
  before_script:
    - export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR
    # Install node and dependencies
    - curl -sL https://deb.nodesource.com/setup_12.x | bash -
    - apt-get update -yq
    - apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y apt-transport-https build-essential cmake nodejs software-properties-common unzip
    # Install yarn
    - wget -q -O - https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
    - echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
    - apt-get update -yq
    - apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y yarn
    - yarn install
    # Bundler and bundle install
    - gem install bundler --no-document
    - bundle install --jobs $(nproc) "${FLAGS[@]}" --path vendor
    # App setup
    - cp config/database.yml.gitlab config/database.yml
    - bundle exec rake db:setup
    - bundle exec rails webpacker:compile
test:rspec:
  extends: .test_app
  stage: test
  artifacts:
    name: coverage_report
    paths:
      - coverage/
  script:
    - bundle exec rspec

@Sakshi1305
Copy link
Author

@BlackRabbitt : Thanks, this is worked but really i faced problem in autodevops ci deployment so i want to know how webpacker worked in autodevops ci deployment or this is not supported yet.

@fa11enangel
Copy link

fa11enangel commented Aug 28, 2020

I run into this bug with a newly generated project on rails 6.0.3.2 upgrading all dependencies (including JS) to current.

By debugging this, the problem seems to be in @rails/webpacker 5.2.X Javascript package as downgrading to 5.1.1 fixed the problem. Running rails with and without webpack-dev-server works fine. But if I try to run bin/rails test he doesn't generate pubic/packs-test resulting in an empty manifest file error you described.

I've found also another issue. If you deploy through capistrano, capistrano will delete all the stuff webpack-dev-server (packs-development) and packs-test on your development machine, which breaks all assets and results in this error. Restarting webpack-dev-server in your development environment helps to fix this.

@jfanals
Copy link

jfanals commented Sep 28, 2020

@Sakshi1305 : did you manage to fix this issue?

@gsar
Copy link

gsar commented Oct 19, 2020

@fa11enangel also seeing this mysterious issue with the missing packs-test directory on circleci since upgrading from webpacker 5.1.1 to 5.2.1. downgrading appears to fix the issue. working around it currently by running rake webpacker:compile in circleci prior to running the tests.

@guillaumebriday
Copy link
Member

Thanks @gsar

perfalle added a commit to perfalle/ansible-mastodon-docker that referenced this issue Sep 19, 2021
@velles
Copy link

velles commented Apr 4, 2022

adding a run step resolved it for me

      # compile assets
      - run: 
          name: run rake assets:precompile
          command: RAILS_ENV=test bundle exec rake assets:precompile

jsugarman added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Dec 22, 2022
jsugarman added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Jan 5, 2023
@jamo254
Copy link

jamo254 commented Dec 16, 2023

@velles where did you add this line?

compile assets

  - run: 
      name: run rake assets:precompile
      command: RAILS_ENV=test bundle exec rake assets:precompile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants