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

Running webpack's script inside Rails project in Windows 10 x64 doesn't work #245

Closed
webpack-bot opened this issue Apr 8, 2017 · 12 comments

Comments

@webpack-bot
Copy link

webpack-bot commented Apr 8, 2017

Do you want to request a feature or report a bug?

BUG

What is the current behavior?

Running webpack's script inside Rails project in Windows 10 x64 doesn't work properly. Same goes for rake webpacker:compile or webpack-watcher. To fix the first issue (bin/webpack) I deleted NODE_PATH=#{NODE_MODULES_PATH} from the exec (line 38)

It seems that the environment must be set before the exec for Windows

If the current behavior is a bug, please provide the steps to reproduce.

For first one:

$ ./bin/webpack
./bin/webpack:38:in `exec': Invalid argument - NODE_PATH=E:/buk/node_modules E:/buk/node_modules/.bin/webpack --config E:/buk/config/webpack/development.js  (Errno::EINVAL)
        from ./bin/webpack:38:in `block in <main>'
        from ./bin/webpack:37:in `chdir'
        from ./bin/webpack:37:in `<main>'

Second one:

$ rake webpacker:compile
Webpacker is installed 🎉 🍰
Using E:/buk/config/webpack/paths.yml file for setting up webpack paths
Compiling webpacker assets 🎉
C:/RailsInstaller/Ruby2.3.0/bin/rake: No such file or directory - NODE_ENV=production ./bin/webpack
rake aborted!
NoMethodError: undefined method `success?' for nil:NilClass

Third one:

$ bin/webpack-watcher
bin/webpack-watcher:9:in `exec': Exec format error - ./webpack --watch --progress --color  (Errno::ENOEXEC)
        from bin/webpack-watcher:9:in `block in <main>'
        from bin/webpack-watcher:8:in `chdir'
        from bin/webpack-watcher:8:in `<main>'

Tasks: TOP => webpacker:compile
(See full trace by running task with --trace)

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

Node.js version: 7.8
Webpack version: 2.3.2
Windows 10 x64


This issue was moved from webpack/webpack#4661 by @sokra. Orginal issue was by @jarrieta86.

@webpack-bot webpack-bot changed the title Running webpack&#x27;s script inside Rails project in Windows 10 x64 doesn&#x27;t work Running webpack's script inside Rails project in Windows 10 x64 doesn't work Apr 8, 2017
@rodoneill
Copy link

Related issue with rails webpacker:install on Windows. To be able to run rails webpacker:install in an existing app on Windows 10 x64, I had to change the install.rake exec command from "./bin/rails app:template..." to just "rails app:template..."

exec "rails app:template LOCATION=#{WEBPACKER_APP_TEMPLATE_PATH}"

I can now install and run other webpacker commands successfully. Not sure if this helps :\

@gauravtiwari
Copy link
Member

@rodoneill Did you dig deeper into this issue? Perhaps, if you can make a PR to fix the issue :)

@ytbryan
Copy link
Contributor

ytbryan commented Apr 25, 2017

I had to change the install.rake exec command from "./bin/rails app:template..." to just "rails app:template..."

./bin/rails is only available on linux right? If using rails app:template solved it, then this is a non-issue?

cc @rodoneill @jarrieta86

@rubys
Copy link
Contributor

rubys commented Apr 25, 2017

The above patch lets me run webpacker install on Windows, and should work on all platforms.

It does mean that if you run Rails with one version of Ruby, the same version of Ruby will be used to run nested commands. Previously, the version of Ruby specified in the #! line at the top of the file was used (a feature common to Unix shells, but not present on Windows).

@fsateler
Copy link
Contributor

It seems this issue has been closed in error, as only the webpacker:install command appears to have been fixed, but bin/webpack* have not. AFAICT, the issue is that VAR=value some_command is not valid cmd syntax, and the exec form in use goes through the shell, which is cmd in the windows case. I believe the correct fix is to use the version that does not go through cmd:

newenv = { "NODE_PATH" => NODE_MODULES_PATH }
cmdline = [WEBPACK_BIN, "--config", WEBPACK_CONFIG] + ARGV

Dir.chdir(APP_PATH) do
  exec newenv, *cmdline
end

@gauravtiwari gauravtiwari reopened this Apr 27, 2017
@gauravtiwari
Copy link
Member

@fsateler Thanks 👍 Want to make a PR for this?

fsateler added a commit to fsateler/webpacker that referenced this issue May 9, 2017
…directly

Windows cmd does not support the ENVVAR=VALUE syntax prepended to a command, so the binstubs did not work
there. To avoid that, use the exec form that does not go via the shell, and instead executes the program directly.

Fixes: rails#245
@ghost
Copy link

ghost commented May 10, 2017

#361 here I use @rubys method to fix the other shell commands in the install scripts. Otherwise the yarn dependencies aren't actually added.

gauravtiwari pushed a commit that referenced this issue May 10, 2017
…directly (#355)

Windows cmd does not support the ENVVAR=VALUE syntax prepended to a command, so the binstubs did not work
there. To avoid that, use the exec form that does not go via the shell, and instead executes the program directly.

Fixes: #245
@fny
Copy link

fny commented Jul 25, 2017

I'm not sure this issue should be closed. I'm still getting the same error when loading webpacker from the Github repository in my Gemfile.

@gauravtiwari
Copy link
Member

@fny Did you upgrade the config files after updating from master?

Gemfile

gem 'webpacker', github: 'rails/webpacker'

(update/replace all files prompted)

bundle update webpacker
bundle exec rails webpacker:install

@fny
Copy link

fny commented Jul 25, 2017

Just tried that and it made no difference. I still see the following error when I try to start the tests:

ActionView::TemplateError:
    Exec format error -- ./bin/webpack

I see the Exec format error when I try to run the dev server to: ./bin/webpack-dev-server

Note this is with a repository that's already working without any issue on my 'nix machines.

@gauravtiwari
Copy link
Member

ruby ./bin/webpack-dev-server you are running this from command line?

@fny
Copy link

fny commented Jul 30, 2017 via email

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

7 participants