webpack Foreman开始讨论Windows 10问题

wdebmtf2  于 2023-01-17  发布在  Webpack
关注(0)|答案(2)|浏览(120)

环境:

  • windows 10 x64
  • Ruby:Ruby2.7.2p137(2020年10月1日修订版本5445e04352)[x64-mingw32]
  • 节点:版本16.13.1
  • 国家预防机制:8.1.2

问题陈述:

在Windows 10 x64中运行Rails项目内的Webpack脚本无法正常工作。
似乎必须在exec for Windows之前设置环境

异常:

工头开始向下投掷错误

$ 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 🎉 🍰
a2mppw5e

a2mppw5e1#

在项目的根目录下添加一个名为“Procfile”的新文件。

web: bundle exec rails server -p $PORT

现在,您将能够使用命令运行服务器

heroku local

网址是http://localhost:5000。

g2ieeal7

g2ieeal72#

我只是简单地运行gem uninstall foremangem install foreman,然后捆绑安装。

相关问题