opalrb

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


Opal looks amazing!!! I'm getting the same "A file required wasn't found" error when I try to require 'opal-jquery' on two different Windows 7 and Windows 10 systems:

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)

The file test.js.rb consists of these 3 lines:

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

The file opal-jquery.rb is present:

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

but the error message indicates that the directory containing this file was not searched.

It works if I remove the require 'opal-jquery' line to create the 2 line file 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

Running both require statements from ruby works fine

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

I've used the Process Monitor utility to monitor all file accesses while opal does the compile. The ruby executable reads the opal-jquery-0.4.3.gemspec file, but doesn't ever try to open any other opal-jquery file. Apparently something in the gemspec is causing this error, but the only runtime dependency is opal < 0.12.0, >= 0.10.0, which should be satisfied by 0.11.4.

I see exactly the same 'A file required by "test.js.rb" wasn't found' error on Ubuntu 16.04, opal 0.11.4, opal-jquery 0.4.3, ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

I'd appreciate any assistance. Thanks!!!


Solution

  • You need to require opal-jquery in ruby-land first or manually append opal-jquery's folder to those checked by opal:

    lib/opal/jquery.rb#L12

    If you want to do that from the CLI you can use RUBYOPT:

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