在Rails中加载webpack javascript时出现EOFError



我有一个文件app/javascript/packs/application.js在我的Rails 6项目。当我加载站点的本地开发版本时,它试图通过http://localhost:4000/packs/js/application-ed3ae63cdf581cdb86b0.js检索(我在自定义端口上运行以避免与另一个应用程序发生冲突),但是对JS文件的请求失败了500:

Puma caught this error: end of file reached (EOFError)
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/protocol.rb:225:in `rbuf_fill'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/protocol.rb:191:in `readuntil'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/protocol.rb:201:in `readline'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http/response.rb:40:in `read_status_line'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http/response.rb:29:in `read_new'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-proxy-0.6.5/lib/net_http_hacked.rb:53:in `begin_request_hacked'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-proxy-0.6.5/lib/rack/http_streaming_response.rb:60:in `response'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-proxy-0.6.5/lib/rack/http_streaming_response.rb:29:in `headers'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:120:in `perform_request'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/webpacker-4.3.0/lib/webpacker/dev_server_proxy.rb:21:in `perform_request'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.3.3/lib/rails/engine.rb:527:in `call'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.6/lib/puma/configuration.rb:228:in `call'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.6/lib/puma/server.rb:713:in `handle_request'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.6/lib/puma/server.rb:472:in `process_client'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.6/lib/puma/server.rb:328:in `block in run'
/Users/sam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/puma-4.3.6/lib/puma/thread_pool.rb:134:in `block in spawn_thread'

这个文件在本地不存在:

$ ls public/packs/js/application-ed3ae63cdf581cdb86b0.js
ls: public/packs/js/application-ed3ae63cdf581cdb86b0.js: No such file or directory

,但另一个指纹的版本可以(并且非空):

$ ls -alh public/packs/js/application-*
-rw-r--r--  1 sam  staff   188K 24 Feb 17:58 public/packs/js/application-fdef50bf044896f1dc71.js
-rw-r--r--  1 sam  staff   212K 24 Feb 17:58 public/packs/js/application-fdef50bf044896f1dc71.js.map

我无法让我的网站请求正确的文件。接下来,我尝试了

rake assets:clean
rake assets:precompile
touch tmp/restart.txt

,但无济于事。我还尝试了一个私人浏览器窗口,清除浏览器缓存和一个不同的浏览器。

我使用bin/server而不是bin/webpacker-dev-server,并没有改变我的webpacker.yml(它是在init上自动创建的,然后在我安装React时自动更新),但如果它有帮助,它看起来像这样:

# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
- .eot
- .otf
- .ttf
- .woff
- .woff2
extensions:
- .jsx
- .mjs
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
pretty: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'

test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Extract and emit a css file
extract_css: true
# Cache manifest.json for performance
cache_manifest: true

我错过了什么?提前感谢!

看到你没有使用开发服务器,你的资产很可能在public/packs中有一个旧版本,这让我想到了几件事。

尝试删除包文件夹并运行bin/server

我在另一个场合遇到了这个问题的变体(同样的错误,但正确名称的文件在public/packs/js),并设法通过不再在自定义端口上运行我的Rails应用程序来解决它。

此外,当我停止该服务器并重新运行它时,重新应用自定义端口,然后在该上下文中正确加载资源。

最新更新