React_on_rails: foreman start in dev Unknown switches '-w'

Created on 13 Oct 2017  路  15Comments  路  Source: shakacode/react_on_rails

I trying this React on Rails Basic Tutorial. But in the step "foreman start -f Procfile.dev" I got this error:

00:25:16 web.1    | started with pid 27599
00:25:16 client.1 | started with pid 27600
00:25:18 client.1 | ReactOnRails: Set generated_assets_dir to default: public/webpack/development
00:25:18 web.1    | => Booting Puma
00:25:18 web.1    | => Rails 5.1.4 application starting in development
00:25:18 web.1    | => Run `rails server -h` for more startup options
00:25:18 web.1    | ReactOnRails: Set generated_assets_dir to default: public/webpack/development
00:25:18 web.1    | Puma starting in single mode...
00:25:18 web.1    | * Version 3.10.0 (ruby 2.4.2-p198), codename: Russell's Teapot
00:25:18 web.1    | * Min threads: 5, max threads: 5
00:25:18 web.1    | * Environment: development
00:25:18 web.1    | * Listening on tcp://localhost:3000
00:25:18 web.1    | Use Ctrl-C to stop
00:25:18 client.1 | Unknown switches '-w'
00:25:19 client.1 | exited with code 15
00:25:19 system   | sending SIGTERM to all processes
00:25:19 web.1    | - Gracefully stopping, waiting for requests to finish
00:25:19 web.1    | === puma shutdown: 2017-10-14 00:25:19 +0700 ===
00:25:19 web.1    | - Goodbye!
00:25:19 web.1    | Exiting
00:25:19 web.1    | terminated by SIGTERM

I using gem and have Procfile.dev like in the Tutorial:

Gemfile

gem 'react_on_rails', '9.0.0'

Procfile.dev

web: rails s -p 3000
# Next line runs a watch process with webpack
client: sh -c 'rm -rf public/packs/* || true && bundle exec rake react_on_rails:locale && bin/webpack -w'
discussion

Most helpful comment

Ok a solution that works without downgrading Bundler is as follows:

rm ./bin/webpack ./bin/webpack-dev-server && bundle binstub webpacker --standalone

This re-generates the binstubs without the 2 extra lines at the start which eat your command line arguments.

All 15 comments

I have the same problem. I've been starting my server without the -w. I think is a bug with webpack as according to the help guide when you run webpack --help the -w or --watch is a valid option.

@heavenlypeach If we remove -w or --watch the watcher won't work right ?
Change bin/webpack -w to webpack -w solved my problem
I don't know what different between bin/webpack and webpack ?
Is it about gem and global webpack ?

@thanhnha1103 it all depends on if you're using the rails binstubs for rails/webpacker. If not, then you're using the real Webpack command.

Thank @justin808,

I just followed the tutorial above step by step, and get error: Unknown switches '-w' when I try foreman start -f Procfile.dev help me explain this.

I still don't understand why.
Thank you again.

See https://github.com/rails/webpacker/issues/959

3.0.2 broke this...

PR anybody?

@thanhnha1103 Can you link me to an example repository? Because I'm having trouble reproducing your issue. See https://github.com/Judahmeek/ror-test for a working example.

@Judahmeek,

I just reproduced this and push code to new repository https://github.com/thanhnha1103/test-react-on-rails

Thank you,

@thanhnha1103 Please see if v10, just shipped, fixes the issue!

@justin808 Thank you and Team for helping me.
After retried many times with 9. versions, @Judahmeek example and v10.
I think there are something from bundler 1.16.0.pre.3 is the root cause.
Because when I tried with same version 1.15.4 as @Judahmeek example, all versions I have tried above worked perfectly.
Thank you.

I ran into the same issue with latest versions of rails (5.1.4), react_on_rails (10.0.0) and bundler (1.16.0.pre.3). This is related to the way Bundler generates the binstubs.

To get around this problem:

  • Downgrade Bundler to 1.15.4
  • Delete the binstubs bin/webpack and bin/webpack-dev-server
  • Run rails webpacker:install and rails webpacker:install:react commands again (Bundler will generate new working binstubs)
  • Upgrade Bundler back to 1.16.0.pre.3

No more Unknown switches '-w' error message!

Hope this helps.

@pguegan 's workaround resolved the error for me. Thanks!

This is caused by Bundler 1.16.0 - I've raised an issue with them https://github.com/bundler/bundler/issues/6149.

For some reason, 1.16.0 adds the following two lines to the top of all generated binstubs:

https://github.com/bundler/bundler/blob/01fe509b27b317dd4d640beb9140ab31331ea349/lib/bundler/templates/Executable#L11-L12

This seems to prevent command line arguments being proxied to the underlying executable. I'm not sure why they're needed, because simply removing those lines fixes the behaviour.

@justin808 Fyi, while webpacker did remove command line arguments in 3.0.2, it was only for the webpack dev server, the webpack runner still proxies arguments through.

Ok a solution that works without downgrading Bundler is as follows:

rm ./bin/webpack ./bin/webpack-dev-server && bundle binstub webpacker --standalone

This re-generates the binstubs without the 2 extra lines at the start which eat your command line arguments.

@johnmcdowall, this changes my bin/webpack to:
load File.expand_path "../../../../../../../../home/jim/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/webpacker-3.2.0/exe/webpack", path.realpath
which works locally but obviously Heroku does not like it..

"For now, the fix is to run bundle binstubs bundler --force"
rails/rails#31193

This changes bin/bundler vs the webpack stuff and works for me now both locally and on Heroku

Was this page helpful?
0 / 5 - 0 ratings