Webpacker: `rails assets:precompile` does not create `/public/packs` directory

Created on 18 Oct 2018  ·  9Comments  ·  Source: rails/webpacker

Hello,

I have a pretty straight-forward rails app that I am deploying using dokku. In development it works fine, but in production I get the error

2018-10-18T07:05:37.632168000Z app[web.1]: [1d5a0a60-b707-41dd-a6d7-648e26e1db66] ActionView::Template::Error (Webpacker can't find app.js in /app/public/packs/manifest.json. Possible causes:
2018-10-18T07:05:37.632171108Z app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2018-10-18T07:05:37.632173344Z app[web.1]:    unless you are using the `webpack -w` or the webpack-dev-server.
2018-10-18T07:05:37.632186203Z app[web.1]: 2. webpack has not yet re-run to reflect updates.
2018-10-18T07:05:37.632188805Z app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2018-10-18T07:05:37.632190932Z app[web.1]: 4. Your webpack configuration is not creating a manifest.
2018-10-18T07:05:37.632193095Z app[web.1]: Your manifest contains:
2018-10-18T07:05:37.632195113Z app[web.1]: {
2018-10-18T07:05:37.632197163Z app[web.1]: }
2018-10-18T07:05:37.632199464Z app[web.1]: ):

Here is 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_output_path: packs
  cache_path: tmp/cache/webpacker

  # 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

  extensions:
    - .coffee
    - .vue
    - .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: true
    # 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
    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: false

  # Cache manifest.json for performance
  cache_manifest: true

In the deployment logs I can see

       Webpacker is installed 🎉 🍰
       Using /tmp/build/config/webpacker.yml file for setting up webpack paths
       Compiling…
       Compiled all packs in /tmp/build/public/packs
       Asset precompilation completed (21.25s)
       Cleaning assets
       Running: rake assets:clean
-----> Detecting rails configuration

But when I ls /app/public, I only get

404.html  422.html  500.html  apple-touch-icon.png  apple-touch-icon-precomposed.png  assets  favicon.ico  robots.txt

Does anybody know what might be amiss?

Most helpful comment

I'm using it with docker and i had to manually run rake webpacker:compile on production and all worked fine. I think i'll put it in my dockerfile

All 9 comments

Similarly,

if I dokku enter app, and compile manually, I get this

$ RAILS_ENV=production rake webpacker:compile
Webpacker is installed 🎉 🍰
Using /app/config/webpacker.yml file for setting up webpack paths
Compiling…
Compiled all packs in /app/public/packs
$ ls /app/public/packs
ls: cannot access '/app/public/packs': No such file or directory

Locally the packs compile just fine...

I was able to nail the issue down to some npm packages not being installed (probably a messed up yarn.lock file or something similar). Reinstalling all yarn packs locally and committing the lock file to the repo fixed the server-side building. Just in case somebody else has a similar issue.

For me it was some people who wrongly put some libs in dev dependencies...

So, assets were compiling fine in development, but not on staging. What is strange is that I got no errors (everything was like @buhrmi said).

Webpacker should complain about missing libraries when it tries to compile and fails to do so, shouldn't it?

What is strange is that I got no errors (everything was like @buhrmi said)

@Kulgar Errors were suppressed to reduce dev server output in development. I feel like this will be a continual source of problems for new users. Here is the commit.

it was some people who wrongly put some libs in dev dependencies...

Discussed at length in this issue.

I'm using it with docker and i had to manually run rake webpacker:compile on production and all worked fine. I think i'll put it in my dockerfile

@mroliveira7 Thanks for the note on Docker, that got it for me as well.

I have deployed the Rails App on AWS EC2 instance using Rails and Unicorn.
But rake webpacker:compile command not generating public/packs even public/assets is created.
I also tried rake assets:precompile RAILS_ENV=production but it was the same.
Anyone can help me?

@nikolacojcic99 Sounds like something might be failing.

Make sure your webpacker.yml ensures compilation logs are printed: webpack_compile_output: true

Inspect the logs at your next deploy to look for errors during the compilation process. From there, folks may be able to help diagnose the specific error.

I have deployed the Rails App on AWS EC2 instance using Rails and Unicorn.
But rake webpacker:compile command not generating public/packs even public/assets is created.
I also tried rake assets:precompile RAILS_ENV=production but it was the same.
Anyone can help me?

Could you fix this? I'm having the same error :(

Was this page helpful?
0 / 5 - 0 ratings