Environment:
- Windows 10 x64
- Ruby: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
- Node: v16.13.1
- npm: 8.1.2
Problem Statement:
Running webpack script inside Rails project in Windows 10 x64 doesn't work properly.
It seems that the environment must be set before the exec for Windows
Exception:
Foreman start throwing below error
$ foreman startTraceback (most recent call last): 17: from C:/Ruby27/bin/foreman:23:in `<main>' 16: from C:/Ruby27/bin/foreman:23:in `load' 15: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/bin/foreman:7:in `<top (required)>' 14: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/vendor/thor/lib/thor/base.rb:444:in `start' 13: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/vendor/thor/lib/thor.rb:369:in `dispatch' 12: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command' 11: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/vendor/thor/lib/thor/command.rb:27:in `run' 10: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/cli.rb:42:in `start' 9: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/engine.rb:57:in `start' 8: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/engine.rb:363:in `spawn_processes' 7: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/engine.rb:363:in `each' 6: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/engine.rb:364:in `block in spawn_processes' 5: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/engine.rb:364:in `upto' 4: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/engine.rb:367:in `block (2 levels) in spawn_processes' 3: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/process.rb:53:in `run' 2: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/process.rb:53:in `chdir' 1: from C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/process.rb:54:in `block in run'C:/Ruby27/lib/ruby/gems/2.7.0/gems/foreman-0.87.2/lib/foreman/process.rb:54:in `spawn': Exec format error - bin/webpack-dev-server (Errno::ENOEXEC)
Configuration:
GemFile
ruby "2.7.2"gem "rails", "~> 6.0"gem "webpacker", "< 6"group :development do gem "foreman", require: falseend
package.json
{"name": "demo","private": true,"engines": {"node": ">=10.15.3","npm": ">=6","yarn": ">=1.15.2" },"dependencies": {"@rails/webpacker": "5.4.3","webpack": "4.46.0","webpack-cli": "3.3.12" },"version": "0.1.0","devDependencies": {"webpack-dev-server": "3" },}
EDIT 1:
However, executing bin/webpack-dev-server
on a separate terminal is compiling properly.
$ bin/webpack-dev-serveri 「wds」: Project is running at http://localhost:3035/i 「wds」: webpack output is served from /packs/i 「wds」: Content not from webpack is served from C:\Users\DELL\path\project\plate\public\packsi 「wds」: 404s will fallback to /index.htmli 「wdm」: Hash: 3f9f73c5cf41d5c81ee8Version: webpack 4.46.0Time: 4740msBuilt at: 12/01/2022 14:01:39 Asset Size Chunks Chunk Names js/application-f0238c055e7bba05cd93.js 515 KiB application [emitted] [immutable] applicationjs/application-f0238c055e7bba05cd93.js.map 581 KiB application [emitted] [dev] application manifest.json 364 bytes [emitted]i 「wdm」: Compiled successfully.
EDIT 2:
I tried removing foreman
from Gemfile
and re-installing it using gem
command by following answer
Gemfile
group :development do # gem "foreman", require: falseend
$ gem uninstall foreman$ gem install foreman
gem uninstall foreman
is removing theforeman
from the ruby main directory itself.
EDIT 3:
I tried bundle exec rails webpacker:install
but again foreman start
is throwing same error. While bin/webpack-dev-server
is compiling properly on PORT as config/webpack
file.
$ bundle exec rails webpacker:install Please add the following to your Gemfile to avoid polling for changes: gem 'wdm', '>= 0.1.0' if Gem.win_platform? Please add the following to your Gemfile to avoid polling for changes: gem 'wdm', '>= 0.1.0' if Gem.win_platform? Please add the following to your Gemfile to avoid polling for changes: gem 'wdm', '>= 0.1.0' if Gem.win_platform? identical config/webpacker.ymlCopying webpack core config exist config/webpack identical config/webpack/development.js identical config/webpack/environment.js identical config/webpack/production.js identical config/webpack/test.jsCopying postcss.config.js to app root directory identical postcss.config.jsCopying babel.config.js to app root directory identical babel.config.jsCopying .browserslistrc to app root directory identical .browserslistrcThe JavaScript app source directory already exists apply C:/Users/DELL/Documents/project/plate/vendor/cache/ruby/2.7.0/gems/webpacker-5.4.3/lib/install/binstubs.rb Copying binstubs exist bin identical bin/webpack identical bin/webpack-dev-serverFile unchanged! The supplied flag value not found! .gitignoreInstalling all JavaScript dependencies [5.4.3] run yarn add @rails/webpacker@5.4.3 from "."yarn add v1.22.15[1/5] Validating package.json...[2/5] Resolving packages...[3/5] Fetching packages...info fsevents@2.3.2: The platform "win32" is incompatible with this module.info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.info fsevents@1.2.13: The platform "win32" is incompatible with this module.info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.[4/5] Linking dependencies...[5/5] Building fresh packages...warning Your current version of Yarn is out of date. The latest version is "1.22.17", while you're on "1.22.15".info To upgrade, download the latest installer at "https://yarnpkg.com/latest.msi".success Saved 0 new dependencies.Done in 8.92s.Installing webpack and webpack-cli as direct dependencies run yarn add webpack@^4.46.0 webpack-cli@^3.3.12 from "."yarn add v1.22.15[1/5] Validating package.json...[2/5] Resolving packages...[3/5] Fetching packages...info fsevents@2.3.2: The platform "win32" is incompatible with this module.info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.info fsevents@1.2.13: The platform "win32" is incompatible with this module.info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.[4/5] Linking dependencies...[5/5] Building fresh packages...success Saved 0 new dependencies.Done in 6.82s.Installing dev server for live reloading run yarn add --dev webpack-dev-server@^3 from "."yarn add v1.22.15[1/5] Validating package.json...[2/5] Resolving packages...[3/5] Fetching packages...info fsevents@2.3.2: The platform "win32" is incompatible with this module.info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.info fsevents@1.2.13: The platform "win32" is incompatible with this module.info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.[4/5] Linking dependencies...[5/5] Building fresh packages...success Saved 0 new dependencies.Done in 7.33s.Webpacker successfully installed 🎉🍰