opal / opal-rails

Bringing Ruby to Rails · Rails bindings for Opal
http://opalrb.com/#getting-started-rails
488 stars 65 forks source link

Loading opal using Sprockets directives causes error #115

Closed caifara closed 1 year ago

caifara commented 4 years ago

Using Rails 6.0.1 and opal-rails 1.1.2:

application.js contains:

//= require opal
Opal.require("opal")

JS-file renders (the page loads), but the browser gives an error:

LoadError: cannot load such file -- corelib/random/MersenneTwister

Converting the file to a application.js.rb solves the problem, but our project combines opal and other javascript, so we need (and would prefer) the sprockets approach.

I guess this commit is causing the problem? https://github.com/opal/opal/commit/3190eedaa5a0d76d50b80028eb0dcf7684433662

elia commented 4 years ago

Ok, so the problem is that corelib/random/MersenneTwister is not being marked as loaded.

Adding Opal.loaded(['corelib/random/MersenneTwister']) before opal (or the opal app) is loaded fixes the problem.

Here's a diff on a pristine new app that has the following output:

> HELLO FROM OPAL APP
> 11
> 336
> 57
> 25
> 167

That said, this is a bug and the instructions on the readme should work

caifara commented 4 years ago

Thanks! Should have asked earlier …

hmdne commented 4 years ago

See also opal/opal#2096

elia commented 1 year ago

Should be fixed by https://github.com/opal/opal/pull/2108