opal-rails icon indicating copy to clipboard operation
opal-rails copied to clipboard

Loading opal using Sprockets directives causes error

Open caifara opened this issue 5 years ago • 3 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? https://github.com/opal/opal/commit/3190eedaa5a0d76d50b80028eb0dcf7684433662

caifara avatar Nov 25 '19 16:11 caifara

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

elia avatar Nov 25 '19 23:11 elia

Thanks! Should have asked earlier …

caifara avatar Nov 26 '19 09:11 caifara

See also opal/opal#2096

hmdne avatar Jul 08 '20 08:07 hmdne

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

elia avatar Jan 26 '23 08:01 elia