0

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
Olliedee
  • 79
  • 2
  • 10

3 Answers3

0

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

0

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.

Olliedee
  • 79
  • 2
  • 10
  • If you would like to try understand what happend. Remove the x86_64-linux and try to deploy. My guess is this was the fix. Since Heroku runs on linux. – AC de Souza Feb 21 '22 at 20:32
  • 1
    I think this was the fix. The fix must be applied via the command line rather than directly editing the.lock, because it doesn't just add the 'platforms' line, it also added a linux-specific version of Noko – Olliedee May 22 '22 at 21:47
  • I totally agree to never edit Gemfile.lock directly. If you remove the Gemfile.lock file and bundle install would it be created with the x86_64-linux? – AC de Souza May 24 '22 at 19:51
  • 1
    No, I run Mac OS locally so it needed the command to be run. If you manually add the platform, it still errors, but you don't get the message telling you to run the command, so it can be tricky to troubleshoot. – Olliedee May 26 '22 at 18:15
0

Encountered this issue when installing the packages using npm via npm install. Switched to yarn via yarn install and its all working for me.

Using rails version 6.1.6 btw.

zekromWex
  • 280
  • 1
  • 4
  • 17