0

GRPC 在这里很适合我:

{
  "errorMessage": "Could not find 'grpc' (~> 1.24) among 281 total gem(s)\nChecked in 'GEM_PATH=/var/task/vendor/bundle/ruby/2.5.0:/opt/ruby/gems/2.5.0:/var/runtime', execute `gem env` for more information",
  "errorType": "Init<Gem::MissingSpecError>",
  "stackTrace": [
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/dependency.rb:311:in `to_specs'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1402:in `block in activate_dependencies'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1391:in `each'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1391:in `activate_dependencies'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1373:in `activate'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems.rb:215:in `rescue in try_activate'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems.rb:208:in `try_activate'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:161:in `rescue in require'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:35:in `require'",
    "/var/task/vendor/bundle/ruby/2.5.0/gems/google-cloud-dialogflow-0.14.0/lib/google/cloud/dialogflow.rb:16:in `<top (required)>'",
    "/var/task/google_dialog.rb:3:in `require_relative'",
    "/var/task/google_dialog.rb:3:in `<top (required)>'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:168:in `require'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:168:in `rescue in require'",
    "/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:35:in `require'"
  ]
}

我看到它在vendor/bundle/ruby/2.5.0/gems/grpc-1.27.0-universal-darwin/src/ruby/lib/grpc.rb

我正在编写一个简单的 Ruby 类来连接到 Dialogflow,而 google gem 相当繁重,有很多依赖项。我已经编写了一些测试,这些测试都在本地通过,并且在我从中提取这段代码的 Rails 应用程序的上下文中通过。我需要 Nokogiri,但 Google 似乎是 GRPC 的大用户。当我手动指定时,它只是找不到该文件。任何帮助是极大的赞赏。

4

1 回答 1

0

在上述问题的情况下 - 操作顺序是我学到的一切。Ruby 是自上而下解析而不是加载所有内容然后解析,我想我应该知道这一点,但 Rails 为您做了很多神奇的事情。

因此,当我看到上述问题时,我的文件顶部有以下要求语句:

require_relative 'vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri.rb'
require_relative 'vendor/bundle/ruby/2.5.0/gems/google-cloud-dialogflow-0.14.0/lib/google/cloud/dialogflow.rb'
require_relative 'vendor/bundle/ruby/2.5.0/gems/google-cloud-dialogflow-0.14.0/lib/google/cloud/dialogflow/v2.rb'
require_relative 'vendor/bundle/ruby/2.5.0/gems/grpc-1.24.0-universal-darwin/src/ruby/lib/grpc.rb'

并且由于在 google cloud ruby​​ 之后需要 grpc

require_relative 'vendor/bundle/ruby/2.5.0/gems/grpc-1.24.0-universal-darwin/src/ruby/lib/grpc.rb'
require_relative 'vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri.rb'
require_relative 'vendor/bundle/ruby/2.5.0/gems/google-cloud-dialogflow-0.14.0/lib/google/cloud/dialogflow.rb'
require_relative 'vendor/bundle/ruby/2.5.0/gems/google-cloud-dialogflow-0.14.0/lib/google/cloud/dialogflow/v2.rb'

只需在 dialogflow 之前放置 grpc 即可解决该问题。

课程 - 总是回到基础。

于 2020-03-06T04:35:37.593 回答