2

My app works fine in development and also in production on my local Mac with config.serve_static_assets = true . However, in production on the Ubuntu 18.04 server I'm getting the following error in NGINX:

No such file to load -- opal_ujs.rb (LoadError)

when I do find . | grep opal_ujs I see the following

./vendor/bundle/ruby/2.5.0/gems/opal-rails-0.9.5/lib/assets/javascripts/opal_ujs.js.rb
./public/assets/opal_ujs-a633a78701574b25c28a62e6892b2a6f2cb93afcd9b71edc9bf5eea75a296481.js.gz
./public/assets/opal_ujs-a633a78701574b25c28a62e6892b2a6f2cb93afcd9b71edc9bf5eea75a296481.js

OK so it's there. Why isn't it being served. The relevant production.rb snippet is as follows:

  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
  config.assets.compile = true
  config.serve_static_assets = false
  config.assets.digest = true

My setup is Phusion Passenger + NGINX. And my NGINX server config for the app has gone through a number of trials but currently is as follows, which another attempt commented out:

server {
        listen 80;
        listen [::]:80;

        server_name myapp.domain;
        passenger_enabled on;
        rails_env    production;
        root         /home/deploy/myapp/current/public;

        # Allow uploads up to 100MB in size
        client_max_body_size 100m;

        #location ~ ^/(assets|packs) {
        # expires max;
        # gzip_static on;
        #}

        # Rails asset pipeline support.

        location ~ ^/assets/ {
          root         /home/deploy/myapp/current/public;
          gzip_static on; # to serve pre-gzipped version
          expires max;
          add_header Cache-Control public;

          # add_header ETag "";
          break;
        }
        # Rails asset pipeline support.
#       location ~ "^/assets/.+-([0-9a-f]{32}|[0-9a-f]{64})\..+" {
#           error_page 490 = @static_asset;
#           error_page 491 = @dynamic_request;
#           recursive_error_pages on;

#           if (-f $request_filename) {
#               return 490;
#           }
#           if (!-f $request_filename) {
#               return 491;
#           }
#       }
#       location @static_asset {
#           gzip_static on;
#           expires max;
#           add_header Cache-Control public;
#           add_header ETag "";
#       }
#       location @dynamic_request {
#           passenger_enabled on;
#       }
}

what am I doing wrong here?

Michael K Madison
  • 2,242
  • 3
  • 21
  • 35
  • Can you show where opal_ujs is being included in the source or what the direct path looks like if it is being requested directly? Also, in your server pop open rails console and check the output of this `Rails.application.assets`, do you see the opal files there? – erosenin Nov 15 '19 at 08:17
  • It's a heavily used gemified set of assets that I have no problem elsewhere. They are load via a regular require. albeit an opal ruby require. The problem seems to be opal actually. Two things eliminated the problem. Updating to the Rails 6 manifest way of loading assets versus filters and competely removing Opal with is quite a bummer. I will add that for example removing the first listed require i.e opal_ujs would facilitate a complaint about the next file. Opal for some reason isn't writing the asset fingerprinting and even though I have digest set to true, etc. – Michael K Madison Nov 17 '19 at 09:37

1 Answers1

-1

You try to load a file named

opal_ujs.rb

and you have this files :

opal_ujs.js.rb

and in assets

opal_ujs-xxxxx.js

maybe it's not the same file.

LiKaZ
  • 306
  • 3
  • 9
  • it is through the asset pipeline, otherwise why would it work locally? Even locally in production mode. Moreover. it's barfing over a require in application.js. It's not like I can specify asset_path for a require. and if I remove opal_ujs from the require it just goes down the list. – Michael K Madison Nov 05 '19 at 10:21