question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React-rails server rendering packs

See original GitHub issue

Help us help you! Have you looked for similar issues? Do you have reproduction steps? Contributing Guide

Steps to reproduce

(Guidelines for creating a bug report are available here)

Expected behavior

Server rendering in production should work the same as in development

Actual behavior

Server rendering in production is not the same.

System configuration

Sprockets or Webpacker version: 4.0 React-Rails version: “~> 2.3.1” React_UJS version: “^2.5.0” Rails version: “~> 5.2.0” Ruby version: “2.6.3”


Hey there!

I’m having this issue for a couple of days now and don’t know how to fix it.

I’m getting the following error on production:

No such file or directory @ rb_sysopen - public/js/server_rendering-7930ba59728fe68ecc97.js

This error is correct since no .js file is present with that name.

The actual path name is:

packs/js/server_rendering-7930ba59728fe68ecc97.js

Any idea where this problem is coming from? This code works perfectly in development but it seems wrong paths get assigned when deploying.

Any help in the right direction would be extremely helpful.

Kind regards Jens

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
KMarshlandcommented, Nov 30, 2021

Note: I believe this is a different issue than the original post, but I’m posting here in case google sent you to this same page. TL;DR: use the edge version of react-rails until they cut a new release or monkey patch it.

I had a similar issue after upgrading from ruby 2.7.2 to 3.0.3. Unlike with naft-a, it works just fine without ./bin/webpack-dev-server running, but fails when it is running, and thus my error is No such file or directory @ rb_sysopen - http://localhost:3035/packs/js/server_rendering-a5bfcb3dc949a5ce125a.js. I can also verify that the javascript is building properly, as going to http://localhost:3035/packs/js/server_rendering-a5bfcb3dc949a5ce125a.js does have the right javascript. Indeed, the root cause of this is in ruby 3 open-uri no longer overwriting Kernel.open (see here for more details). react-rails hadn’t updated webpacker_manifest_container.rb to call URI.open instead of just open until this commit.

Here’s the kicker: that commit, which fixes things, was on 2021-01-02, whereas as of the time of this post the latest version of react-rails on rubygems.org is 2.6.1, released on 2019-12-31. As such, there are three options for how to fix this:

  1. Use the edge version, ie gem 'react-rails', git: 'https://github.com/reactjs/react-rails' in your gemfile. This is a bit risky, as it could add instability as they do development
  2. Make the edit in that commit manually, ie changing line 47 of lib/react/server_rendering/webpacker_manifest_container.rb to use URI.open. Personally I’d avoid this, as you have to do this on every machine you do dev on.
  3. Monkey patch it. See below for my code, which I put in config/initializers/react_rails_patch.rb. This is admittedly a hack, but it’s at least pretty limited in scope.
module React
  module ServerRendering
    class WebpackerManifestContainer
      def open(uri)
        return URI.open(uri) if uri.start_with? 'http://'

        Kernel.open(uri)
      end
    end
  end
end
2reactions
binyamindavidcommented, Sep 14, 2019

I had exactly the same issue in development, running ./bin/webpack-dev-server fixes it. Maybe webpacker does not compile the correct packs on the go?

I confirm that this is the problem

./bin/webpack-dev-server
Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Rendering React on Rails | Cloudbees Blog
In this article, we are going to talk about doing server rendering with our React components inside of Rails. An article by Tom...
Read more >
Single Page ReactJS Applications and Server Side Rendering ...
Rails /Webpacker is a great gem to take advantage of modern front-end javascript frameworks like ReactJS. There are a lot of gems that...
Read more >
How to use React with Ruby on Rails 6 - Learnetto
There are a few different ways to use React inside Ruby on Rails apps. ... configuration for mounting components and server-side rendering.
Read more >
How To Set Up a Ruby on Rails v5 Project with a React ...
jsx set up, it's time to render it in your entry file. Open the entry Index.jsx file: nano ~/rails_react_recipe/app/javascript/packs/Index.jsx.
Read more >
React on Rails: Building a Simple App - Honeybadger.io
If you start the Rails server through the rails s command, this will be the ... app/javascript/packs/hello_react.jsx file to index.jsx.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found