【发布时间】:2022-01-12 08:36:49
【问题描述】:
环境:
- Windows 10 x64
- Ruby:ruby 2.7.2p137(2020-10-01 修订版 5445e04352)[x64-mingw32]
- 节点:v16.13.1
- npm: 8.1.2
问题陈述:
在 Windows 10 x64 的 Rails 项目中运行 webpack 脚本无法正常工作。
看来Windows的exec之前必须设置环境
例外:
工头开始抛出错误
$ foreman start
Traceback (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)
配置:
GemFile
ruby "2.7.2"
gem "rails", "~> 6.0"
gem "webpacker", "< 6"
group :development do
gem "foreman", require: false
end
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"
},
}
编辑 1:
但是,在单独的终端上执行bin/webpack-dev-server 可以正确编译。
$ bin/webpack-dev-server
i 「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\packs
i 「wds」: 404s will fallback to /index.html
i 「wdm」: Hash: 3f9f73c5cf41d5c81ee8
Version: webpack 4.46.0
Time: 4740ms
Built at: 12/01/2022 14:01:39
Asset Size Chunks Chunk Names
js/application-f0238c055e7bba05cd93.js 515 KiB application [emitted] [immutable] application
js/application-f0238c055e7bba05cd93.js.map 581 KiB application [emitted] [dev] application
manifest.json 364 bytes [emitted]
i 「wdm」: Compiled successfully.
编辑 2:
我尝试从Gemfile 中删除foreman 并使用following answer 的gem 命令重新安装它
Gemfile
group :development do
# gem "foreman", require: false
end
$ gem uninstall foreman
$ gem install foreman
gem uninstall foreman正在从 ruby 主目录本身中删除foreman。
编辑 3:
我试过bundle exec rails webpacker:install,但foreman start 再次抛出同样的错误。虽然bin/webpack-dev-server 在端口上正确编译为config/webpack 文件。
$ 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.yml
Copying 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.js
Copying postcss.config.js to app root directory
identical postcss.config.js
Copying babel.config.js to app root directory
identical babel.config.js
Copying .browserslistrc to app root directory
identical .browserslistrc
The 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-server
File unchanged! The supplied flag value not found! .gitignore
Installing 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 ???? ????
【问题讨论】:
标签: ruby-on-rails ruby webpack webpack-dev-server foreman