require 'opal-jquery' gives error: A file required wasn't found

require 'opal-jquery' gives error: A file required wasn't found

蛋白石看起来棒极了!!!当我尝试在两个不同的 Windows 7 和 Windows 10 系统上要求 'opal-jquery' 时,我遇到了相同的 "A file required wasn't found" 错误:

C:\opaltest>node --version
v10.15.3

C:\opaltest>ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x64-mingw32]

C:\opaltest>gem list -a opal

*** LOCAL GEMS ***

opal (0.11.4)
opal-jquery (0.4.3)

文件 test.js.rb 由以下 3 行组成:

require 'opal'
require 'opal-jquery'
puts 'success'
C:\opaltest>opal -c test.js.rb > test.js
Traceback (most recent call last):
        12: from C:/Ruby/Ruby250-1-x64/bin/opal:23:in `<main>'
        11: from C:/Ruby/Ruby250-1-x64/bin/opal:23:in `load'
        10: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/exe/opal:24:in `<top (required)>'
         9: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/cli.rb:65:in `run'
         8: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/cli.rb:87:in `builder'
         7: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/cli.rb:116:in `create_builder'
         6: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/cli.rb:156:in `evals_or_file'
         5: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/cli.rb:116:in `block in create_builder'
         4: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/builder.rb:89:in `build_str'
         3: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/builder.rb:89:in `map'
         2: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/builder.rb:89:in `block in build_str'
         1: from C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/builder.rb:189:in `process_require'
C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib/opal/builder.rb:174:in `read': A file required by "test.js.rb" wasn't found. (Opal::Builder::MissingRequire)
can't find file: "opal-jquery" in:
- C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/opal
- C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/stdlib
- C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/opal-0.11.4/lib
- C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/ast-2.4.0/lib
- C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/ast-2.4.0/lib
- C:/Ruby/Ruby250-1-x64/lib/ruby/gems/2.5.0/gems/parser-2.3.3.1/lib

With the following extensions:
- .js
- .js.js
- .rb
- .js.rb
- .opal
- .js.opal
- .opalerb
- .js.opalerb
- .erb
- .js.erb

And the following processors:
- Opal::BuilderProcessors::JsProcessor
- Opal::BuilderProcessors::RubyProcessor
- Opal::BuilderProcessors::OpalERBProcessor
- Opal::BuilderProcessors::ERBProcessor

存在文件 opal-jquery.rb:

C:\Ruby\Ruby250-1-x64\lib\ruby\gems.5.0\gems\opal-jquery-0.4.3\lib\opal-jquery.rb

但错误消息表明未搜索包含此文件的目录。

如果我删除 require 'opal-jquery' 行来创建 2 行文件 test_without_jquery.js.rb:

require 'opal'
puts 'success'
C:\opaltest>opal -c test_without_jquery.js.rb > test_without_jquery.js

C:\opaltest>node test_without_jquery.js
success

运行 都需要来自 ruby 的语句工作正常

C:\opaltest>ruby test.js.rb
success

我使用 Process Monitor 实用程序来监视所有文件访问,同时 opal 进行编译。 ruby 可执行文件读取 opal-jquery-0.4.3.gemspec 文件,但不会尝试打开任何其他 opal-jquery 文件。显然是 gemspec 中的某些东西导致了这个错误,但唯一的运行时依赖是 opal < 0.12.0, >= 0.10.0,0.11.4 应该满足它。

我在 Ubuntu 16.04、opal 0.11.4、opal-jquery 0.4.3 上看到完全相同的“未找到 "test.js.rb" 所需的文件”错误, ruby 2.3.1p112(2016-04-26 修订版 54768)[x86_64-linux]

如有任何帮助,我将不胜感激。谢谢!!!

您需要先在 ruby-land 中要求 opal-jquery 或手动将 opal-jquery 的文件夹附加到 opal 检查的文件夹中:

lib/opal/jquery.rb#L12

如果您想从 CLI 执行此操作,您可以使用 RUBYOPT:

export RUBYOPT="-ropal-jquery"
opal -c test.js.rb > test.js