Home > Mobile >  Webpacker can't find application.js in /app/public/packs/manifest.json and I can't precomp
Webpacker can't find application.js in /app/public/packs/manifest.json and I can't precomp

Time:02-19

I am using Ruby 2.7.1, Rails 5.2, Webpacker 5.4.3. I have just installed Stimulus and Webpacker to add a bit of functionality.

I'm only using scss and not via webpacker. All I have added webpacker for is one single stimulus controller and action.

I have also added the nodejs buildpack to Heroku, and it is placed above my Ruby buildpack.

It's all working fine locally, but when I deploy to Heroku I'm getting the error below.

I have tried most of the SO threads, including all of the steps in Rails: Webpacker 4.2 can't find application in /app/public/packs/manifest.json heroku

I then get this other error when loading a page:

ActionView::Template::Error (Webpacker can't find application.js in /app/public/packs/manifest.json. Possible causes:
2022-02-17T00:23:41.046861 00:00 app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2022-02-17T00:23:41.046862 00:00 app[web.1]: unless you are using the `webpack -w` or the webpack-dev-server.
2022-02-17T00:23:41.046862 00:00 app[web.1]: 2. webpack has not yet re-run to reflect updates.
2022-02-17T00:23:41.046863 00:00 app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2022-02-17T00:23:41.046863 00:00 app[web.1]: 4. Your webpack configuration is not creating a manifest.
2022-02-17T00:23:41.046864 00:00 app[web.1]: Your manifest contains:
2022-02-17T00:23:41.046864 00:00 app[web.1]: {
2022-02-17T00:23:41.046864 00:00 app[web.1]: }
2022-02-17T00:23:41.046865 00:00 app[web.1]: ):
2022-02-17T00:23:41.049630 00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]      7:
2022-02-17T00:23:41.049632 00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]      8:     <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
2022-02-17T00:23:41.049633 00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]      9:     <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
2022-02-17T00:23:41.049645 00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]     10:     <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
2022-02-17T00:23:41.049652 00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]     11:     <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
2022-02-17T00:23:41.049652 00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]     12:
2022-02-17T00:23:41.049653 00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]     13:     <%= action_cable_meta_tag %>
2022-02-17T00:23:41.049678 00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]
2022-02-17T00:23:41.049817 00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a] app/views/layouts/application.html.erb:10:in `_app_views_layouts_application_html_erb___2567613171312260909_150400'

My webpacker.yml:

  # Note: You must restart bin/webpack-dev-server for changes to take effect

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

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

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

  # Extract and emit a css file
  extract_css: false

  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

  # 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 precompilation of packs prior to booting for performance.
  compile: true

  # Extract and emit a css file
  extract_css: false

  # Cache manifest.json for performance
  cache_manifest: true

Application.html.erb:

  <head>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <%= csrf_meta_tags %>
    
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">

    <%= action_cable_meta_tag %>
    <%= render 'content/cookie_consent' %>
  </head>

manifest.json from heroku server:

{
  "application.js": "/packs/js/application-7cfb688d908cd6b44d3a.js",
  "application.js.map": "/packs/js/application-7cfb688d908cd6b44d3a.js.map",
  "entrypoints": {
    "application": {
      "js": [
        "/packs/js/application-7cfb688d908cd6b44d3a.js"
      ],
      "js.map": [
        "/packs/js/application-7cfb688d908cd6b44d3a.js.map"
      ]
    }
  }
}

app/javascript/packs/application.js:

import "controllers"
import '../stylesheets/application'; // have tried it both with and without this included

CodePudding user response:

Could you provide your full webpacker.yml?

Maybe you're missing something in the default?

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

Maybe this could help?

https://github.com/rails/webpacker/issues/2674

CodePudding user response:

I'm not sure how this ended up getting resolved.

I updated my Ruby to 2.7.5 from 2.7.1 bundle install

I had a message to install Graphviz, to gemfile I added:

gem 'ruby-graphviz', '~> 1.2', '>= 1.2.3'

bundle install

locally ran:

rake assets:precompile

Added to gemfile.lock

PLATFORMS
  x86_64-darwin-21 //this existed
  x86_64-linux //this was added

Pushed to Heroku and it worked.

  • Related