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

foreman start in dev Unknown switches '-w' #956

Closed
thanhnha1103 opened this issue Oct 13, 2017 · 15 comments
Closed

foreman start in dev Unknown switches '-w' #956

thanhnha1103 opened this issue Oct 13, 2017 · 15 comments

Comments

@thanhnha1103
Copy link

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'
@thanhnha1103 thanhnha1103 changed the title Unknown switches '-w' when foreman start -f Procfile.dev foreman start in dev Unknown switches '-w' Oct 13, 2017
@mccasey
Copy link

mccasey commented Oct 13, 2017

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.

@thanhnha1103
Copy link
Author

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

@justin808
Copy link
Member

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

@thanhnha1103
Copy link
Author

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.

@justin808
Copy link
Member

See rails/webpacker#959

3.0.2 broke this...

PR anybody?

@justin808 justin808 reopened this Oct 16, 2017
@Judahmeek
Copy link
Contributor

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

@thanhnha1103
Copy link
Author

@Judahmeek,

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

Thank you,

@justin808
Copy link
Member

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

@thanhnha1103
Copy link
Author

thanhnha1103 commented Oct 17, 2017

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

@pguegan
Copy link

pguegan commented Oct 27, 2017

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.

@tarnelope
Copy link

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

@jmdfm
Copy link

jmdfm commented Nov 3, 2017

This is caused by Bundler 1.16.0 - I've raised an issue with them rubygems/bundler#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.

@jmdfm
Copy link

jmdfm commented Nov 3, 2017

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.

@JimW
Copy link

JimW commented Dec 19, 2017

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

@JimW
Copy link

JimW commented Dec 23, 2017

"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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants