opal/opal-rails

Loading opal using Sprockets directives causes error

caifara opened this issue · 4 comments

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? opal/opal@3190eed

elia commented

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

Thanks! Should have asked earlier …

hmdne commented
elia commented

Should be fixed by opal/opal#2108