簡體   English   中英

無法在軌道上運行 ruby

[英]Unable to run ruby on rails

我很困惑是我沒有下載東西還是文件不可執行,導致無法通過 git 在 Rails 上運行 ruby​​。

$ rails s
=> Booting Puma
=> Rails 7.0.3 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:159:in `rescue in create_default_data_source': tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install (TZInfo::DataSourceNotFound)
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:156:in `create_default_data_source'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:55:in `block in get'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:54:in `synchronize'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:54:in `get'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-7.0.3/lib/active_support/railtie.rb:88:in `block in <class:Railtie>'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:32:in `instance_exec'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:32:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:61:in `block in run_initializers'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `each'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `call'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:60:in `run_initializers'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/application.rb:372:in `initialize!'
        from D:/rails/project1/config/environment.rb:5:in `<main>'
        from config.ru:3:in `require_relative'
        from config.ru:3:in `block in <main>'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:116:in `eval'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:116:in `new_from_string'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:105:in `load_file'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:66:in `parse_file'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/server.rb:349:in `build_app_and_options_from_config'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/server.rb:249:in `app'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/server.rb:422:in `wrapped_app'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:76:in `log_to_stdout'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:36:in `start'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:143:in `block in perform'
        from <internal:kernel>:90:in `tap'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:134:in `perform'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/command/base.rb:87:in `perform'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/command.rb:48:in `invoke'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands.rb:18:in `<main>'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from bin/rails:4:in `<main>'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_sources/zoneinfo_data_source.rb:232:in `initialize': None of the paths included in TZInfo::DataSources::ZoneinfoDataSource.search_path are valid zoneinfo directories. (TZInfo::DataSources::ZoneinfoDirectoryNotFound)
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:157:in `new'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:157:in `create_default_data_source'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:55:in `block in get'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:54:in `synchronize'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:54:in `get'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-7.0.3/lib/active_support/railtie.rb:88:in `block in <class:Railtie>'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:32:in `instance_exec'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:32:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:61:in `block in run_initializers'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `each'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `call'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'
        from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:60:in `run_initializers'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/application.rb:372:in `initialize!'
        from D:/rails/project1/config/environment.rb:5:in `<main>'
        from config.ru:3:in `require_relative'
        from config.ru:3:in `block in <main>'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:116:in `eval'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:116:in `new_from_string'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:105:in `load_file'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:66:in `parse_file'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/server.rb:349:in `build_app_and_options_from_config'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/server.rb:249:in `app'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/server.rb:422:in `wrapped_app'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:76:in `log_to_stdout'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:36:in `start'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:143:in `block in perform'
        from <internal:kernel>:90:in `tap'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:134:in `perform'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/command/base.rb:87:in `perform'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/command.rb:48:in `invoke'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands.rb:18:in `<main>'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from bin/rails:4:in `<main>'

我試過'gem install tzinfo-data'

$ gem install tzinfo-data
Successfully installed tzinfo-data-1.2022.1
Parsing documentation for tzinfo-data-1.2022.1
Done installing documentation for tzinfo-data after 1 seconds
1 gem installed

試過'gem install tzinfo'

$ gem install tzinfo
Successfully installed tzinfo-2.0.4
Parsing documentation for tzinfo-2.0.4
Done installing documentation for tzinfo after 2 seconds
1 gem installed

但沒有任何改變,我仍然遇到同樣的錯誤。

然后,我檢查我的 yarn、nodejs、ruby、rails 和 git 是否是最新的:

$ rails -v
Rails 7.0.3

$ yarn -v
1.22.19

$ git --version
git version 2.36.1.windows.1

$ node -v
v18.4.0

$ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]

他們似乎是最新的。

總之......我認為我的寶石中缺少一些東西,但我不知道它是什么。

嘗試從 Gemfile 捆綁這個 gem,而不是直接添加。

將此添加到您的 Gemfile 並運行bundle install

  # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
  gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

希望這可以解決問題。

首先檢查tzinfo-data gem 是否在您的 gemfile 中。

它可能如下所示: cat Gemfile | grep tz cat Gemfile | grep tz

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

嘗試運行:

bundle install

解決方案2:

  1. 首先將您的 Gemfile 重命名為 old.Gemfile mv Gemfile old.Gemfile
  2. 然后touch Gemfile
  3. 然后bundle clean (這將重新安裝寶石)
  4. 刪除 gemfile 並重命名舊的
rm Gemfile
mv old.Gemfile Gemfile
  1. 最后bundle install

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM