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

rails assets:precompile does not create /public/packs directory #1759

Closed
buhrmi opened this issue Oct 18, 2018 · 13 comments
Closed

rails assets:precompile does not create /public/packs directory #1759

buhrmi opened this issue Oct 18, 2018 · 13 comments

Comments

@buhrmi
Copy link

buhrmi commented Oct 18, 2018

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?

@buhrmi
Copy link
Author

buhrmi commented Oct 18, 2018

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...

@buhrmi
Copy link
Author

buhrmi commented Oct 22, 2018

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.

@buhrmi buhrmi closed this as completed Oct 22, 2018
@Kulgar
Copy link

Kulgar commented Feb 12, 2019

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?

@jakeNiemiec
Copy link
Member

jakeNiemiec commented Feb 12, 2019

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.

@mroliveira7
Copy link

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

@cazBlue
Copy link

cazBlue commented Oct 18, 2019

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

@ghost
Copy link

ghost commented Aug 5, 2020

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?

@rossta
Copy link
Member

rossta commented Aug 5, 2020

@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.

@dfvasquez
Copy link

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 :(

@Shalashtein
Copy link

Bumping I've got the same issue while deploying to AWS EB

@selcuktoklucu
Copy link

I've been trying to figure this issue for a long time, and still didn't get a solution yet. I'm working on Heroku, I get this error in these two different scenarios:
Upgrading yarn version to 2
Upgrading rails version to 6.1 from 6.0.3.x

In both of these I had to upgrade webpacker version from 4.2.2, to any version 5.x
I don't see any errors in Heroku deployment logs, but when I visit the main page, I got you mentioned above, basically empty manifest.json file.

I login to heroku bash, and tried to compile manually, and here is the result.

bundle exec rails webpacker:compile
..
..
..
Compiling...
Compiled all packs in /app/public/packs
$ ls /app/public/packs
ls: cannot access '/app/public/packs': No such file or directory

Ideally, after running this command, we should see a manifest.json file with some content and js directory which has several compiled css and js files in it.
In some cases, this can be in <project>/public/packs path, but it not there either.

So it doesn't throw any error, but it also doesn't compile. I also tried rails assets:precompile the result is the same.

@samahmadsam
Copy link

bundle exec rails webpacker:compile

when i run this command so got a error webpack not found any suggestion plz why this error is coming

@James-Wilkinson-git
Copy link

Also having the same problem on webpacker 5 ran rake assets preconoile on heroku and got a notice that Webpack-cli wasn’t there so trying to move it to dependency instead if dev dependency.

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