Ruby bundle exec

Posted

技术标签:

【中文标题】Ruby bundle exec【英文标题】: s 【发布时间】:2021-09-22 01:56:10 【问题描述】:

构建一个 rails 应用程序,过去几周一切正常,在 react 应用程序上使用 ruby​​ on rails 也是如此。

我用 \ 示例 bundle exec rails s\ 输入错误 bundle exec rails s 并且终端将其识别为新行,我只是控制 c 出来,在推送到 git 后,我​​使用上面的命令再次在本地运行程序我返回以下错误。

我尝试了rails sbundle exec rails c 的相同错误我尝试使用--force 和npm 包重新安装ruby gem。

我什至不知道从哪里开始出现这个错误。

我对 ruby​​ 和 rails 还很陌生。我不明白这个错误是如何或从哪里开始的,之前一切都很好。

    => Run `bin/rails server --help` for more startup options
Exiting
Traceback (most recent call last):
        56: from bin/rails:4:in `<main>'
        55: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        54: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        53: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        52: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        51: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        50: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in `<main>'
        49: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/command.rb:50:in `invoke'
        48: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/command/base.rb:69:in `perform'
        47: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        46: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
        45: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
        44: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/server/server_command.rb:135:in `perform'
        43: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/server/server_command.rb:135:in `tap'
        42: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/server/server_command.rb:144:in `block in perform'
        41: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/server/server_command.rb:37:in `start'
        40: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/server/server_command.rb:77:in `log_to_stdout'
        39: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'
        38: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'
        37: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'
        36: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'
        35: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'
        34: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'
        33: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval'
        32: from config.ru:3:in `block in <main>'
        31: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:53:in `require_relative'
        30: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:332:in `require'
        29: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:299:in `load_dependency'
        28: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:332:in `block in require'
        27: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        26: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        25: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        24: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        23: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        22: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        21: from /Users/machine5739/Desktop/greenroads-admin/config/environment.rb:5:in `<main>'
        20: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/application.rb:384:in `initialize!'
        19: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/initializable.rb:60:in `run_initializers'
        18: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/2.7.0/tsort.rb:205:in `tsort_each'
        17: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/2.7.0/tsort.rb:226:in `tsort_each'
        16: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/2.7.0/tsort.rb:347:in `each_strongly_connected_component'
        15: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/2.7.0/tsort.rb:347:in `call'
        14: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/2.7.0/tsort.rb:347:in `each'
        13: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/2.7.0/tsort.rb:349:in `block in each_strongly_connected_component'
        12: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/2.7.0/tsort.rb:431:in `each_strongly_connected_component_from'
        11: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/2.7.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        10: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/2.7.0/tsort.rb:228:in `block in tsort_each'
         9: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/initializable.rb:61:in `block in run_initializers'
         8: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/initializable.rb:32:in `run'
         7: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/initializable.rb:32:in `instance_exec'
         6: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/webpacker-5.4.0/lib/webpacker/railtie.rb:41:in `block in <class:Engine>'
         5: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/webpacker-5.4.0/lib/webpacker.rb:35:in `bootstrap'
         4: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/webpacker-5.4.0/lib/webpacker/commands.rb:47:in `bootstrap'
         3: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/webpacker-5.4.0/lib/webpacker/manifest.rb:18:in `refresh'
         2: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/webpacker-5.4.0/lib/webpacker/manifest.rb:84:in `load'
         1: from /Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/common.rb:216:in `parse'
/Users/machine5739/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/pure/parser.rb:121:in `parse': source is not valid JSON! (JSON::ParserError)

【问题讨论】:

快速浏览一下 webpacker 代码,看起来您的 manifest.json 已损坏。尝试运行 rails webpacker:clobber 来清除现有的编译输出,然后再试一次。 【参考方案1】:

有没有可能是 bootsnap 缓存损坏? 尝试在您的项目文件夹中删除tmp/cache(或您可以在config/boot.rb 中配置的任何其他路径以用于引导快照),也可以尝试使用spring stop,以防它在您的项目中运行。

【讨论】:

以上是关于Ruby bundle exec的主要内容,如果未能解决你的问题,请参考以下文章

整理Ruby相关的各种概念(rvm, gem, bundle, rake, rails等)

Ruby bundle exec

markdown Ruby bundle install中出现奇怪的OpenSSL错误

使用 Docker 镜像运行 bundle install 会忽略 bundle config 设置

Ruby(bundle install,bundle update)FAILS无法安装gems http_parser.rb,eventmachine

在Ruby中捆绑gem加载错误