在 Rails 中加载 webpack javascript 时出现 EOFError
EOFError when loading webpack javascript in Rails
我的 Rails 6 项目中有一个文件 app/javascript/packs/application.js
。当我加载站点的本地开发版本时,它会尝试通过 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
我无法让我的站点请求正确的文件。在 this 之后,我尝试了
rake assets:clean
rake assets:precompile
touch tmp/restart.txt
但无济于事。我还尝试了私人浏览器 window、清除浏览器缓存和其他浏览器。
我正在使用 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
中有旧版本的资产。
尝试删除 packs 文件夹和 运行 bin/server
我在另一个场合遇到了这个问题的变体(同样的错误,但是正确名称的文件 是 在 public/packs/js
中)并且成功地解决了它在自定义端口上 运行 我的 Rails 应用更长。
此外,当我随后停止该服务器并重新运行它并重新应用自定义端口时,资产也会在该上下文中正确加载。
我的 Rails 6 项目中有一个文件 app/javascript/packs/application.js
。当我加载站点的本地开发版本时,它会尝试通过 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
我无法让我的站点请求正确的文件。在 this 之后,我尝试了
rake assets:clean
rake assets:precompile
touch tmp/restart.txt
但无济于事。我还尝试了私人浏览器 window、清除浏览器缓存和其他浏览器。
我正在使用 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
中有旧版本的资产。
尝试删除 packs 文件夹和 运行 bin/server
我在另一个场合遇到了这个问题的变体(同样的错误,但是正确名称的文件 是 在 public/packs/js
中)并且成功地解决了它在自定义端口上 运行 我的 Rails 应用更长。
此外,当我随后停止该服务器并重新运行它并重新应用自定义端口时,资产也会在该上下文中正确加载。