webpacker icon indicating copy to clipboard operation
webpacker copied to clipboard

Rails `assets:precompile` does not compile the assets to `public/packs`

Open vtno opened this issue 8 years ago • 3 comments

My Env: Ruby 2.5.0 Rails 5.2.0 RAILS_ENV : production NODE_ENV : not set Webpacker: master branch Node: v10.1.0 Yarn: 1.7.0

I just upgraded to webpacker4 and tries to run assets:precompile which should run wepacker:compile hook and output them in public/packs.

The log actually tells me that it gets compiled

Using /[APP-PATH]/config/webpacker.yml file for setting up webpack paths
Compiling…
Compiled all packs in /[APP-PATH]/public/packs

Nothing gets compiled. No public/packs folder. I also tried follow the instruction in https://github.com/rails/webpacker/issues/1494

  • Deleting bin/webpack and runwebpacker:binstubs
  • Deleting public/assets and public/packs

but it still doesn't do anything accept outputting the log.

Now the weird part is when I run webpacker:compile it actually gets compiled correctly. (it also shows the same log)

Do I need to run webpacker:compile separately now? or I do I need to change some config etc? Please advice.

My webpacker.yml (I use app/webpack folder instead of app/javascript/packs)

# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
  source_path: app/webpack
  source_entry_path: "./"
  public_output_path: packs
  cache_path: tmp/cache/webpacker

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

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

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

development:
  <<: *default
  compile: false

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

staging:
  <<: *default

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

  # Cache manifest.json for performance
  cache_manifest: true

vtno avatar Jun 08 '18 03:06 vtno

After some deep investigations, It was my package.json that causes the problem. My webpack-cli is in devDependencies so when it's deploying to production it's not getting installed by yarn.

I think when yarn doesn't install webpack-cli it should throw some kind of error instead of telling that it got compiled in public/packs path but actually there's nothing.

vtno avatar Jun 08 '18 07:06 vtno

I had this exact same issue. FWIW, it only started for me when upgrading webpack-cli from 2.1.4 to 2.1.5. It works fine on version 2.1.4, but any version after that didn't work for me. Moving the dependency out of devDependencies fixed the issue for me.

codebycliff avatar Jun 11 '18 15:06 codebycliff

Thanks @vtno - that worked for me. FWIW I'm on webpack-cli 3.0.8 so versions didn't matter, it was just moving it out of devDependencies and into dependencies

Looks like the messaging could be improved from here https://github.com/rails/webpacker/blob/master/lib/webpacker/compiler.rb#L69

jeffsee55 avatar Jul 25 '18 05:07 jeffsee55