These are chat archives for opal/opal

Aug 2018
Elia Schito
Aug 24 2018 13:07
@ryanprior might be a bug, can you provide a way to reproduce? which version you're running on?
Ryan Prior
Aug 24 2018 16:09

Attempting a minimal reproduction, I saved this as test.rb:

require 'base64'

data = 'this is a test string'
data_encoded = ::Base64.encode64(data)

puts "#{data} -b64-> #{data_encoded}"

then ran opal test.rb which worked fine! so let me go try and reproduce in the codebase where I was originally having a problem.

Opal.RUBY_ENGINE_VERSION reports "0.11.1", is that a useful number?
Forrest Chang
Aug 24 2018 16:50
@ryanprior I suspect the problem is that you need to require 'base64' outside the method. Unlike MRI which can do requires in real time, the requires are done at compile time for opal
which makes sense because we're transpiling to javascript to run most times in a browser which would have no access to the filesystem to do a real time require
Aug 24 2018 16:54 Forrest Chang (Gitter): thank you! I moved my require to the top level (in application.rb) and that resolves the issue. It also explains why my attempt at minimal reproduction worked while my actual use case wasn't working.
Ryan Prior
Aug 24 2018 17:01
Hmm, less than ideal how my reply via Matrix bridge gets posted as @matrixbot. I gotta figure out if it's possible to have it use my actual user.
Elia Schito
Aug 24 2018 17:14
@ryanprior @fkchang I'll give it a try anyway, I was sure requires were picked anywhere in the code
btw the require is executed at compile time, but needs to be "detected" at compile time to prepare the code that will be loaded in the js bundle.