Skip to content

Javascript runtime required in production #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AirWick219 opened this issue Mar 21, 2018 · 9 comments
Closed

Javascript runtime required in production #886

AirWick219 opened this issue Mar 21, 2018 · 9 comments
Labels

Comments

@AirWick219
Copy link

AirWick219 commented Mar 21, 2018

System configuration

Sprockets or Webpacker version: webpacker ^3.3.1
React-Rails version: 2.4.4
Rect_UJS version: ^2.4.4
Rails version: ~> 5.1
Ruby version: 2.4.1


Just added react-rails to our app and we are trying to compile the assets with docker for porduction
We encounter this JavaScript runtime error when trying to start the server. But this error goes away if I add gem 'therubyracer' to my gem file. My question is do we absolutely need therubyracer gem even if we are not doing any server side rendering ?? Not sure if i miss it in the readme somewhere.

Dockerfile
From ...

WORKDIR /opt/app

RUN yum -y install git mysql-devel

COPY Gemfile Gemfile.lock package.json .npmrc yarn.lock /opt/app/
RUN bundle install --without development,test

COPY . /opt/app

# Remove anything added to build
RUN curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - && \
    curl -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo && \
    yum install -y nodejs yarn && \
    yarn install && \
    bundle exec rake assets:precompile && \
    rm -rf node_modules && \
    yum autoremove -y nodejs && \
    yum -y clean all


Console


Message from application: There was an error while trying to load the gem 'react-rails'.
| Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
| Backtrace for gem load error is:
| /usr/local/bundle/gems/execjs-2.7.0/lib/execjs/runtimes.rb:58:in `autodetect'
| /usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:5:in `<module:ExecJS>'
@BookOfGreg
Copy link
Member

I'll look into it, fair point that it shouldn't be needed server-side if it's already compiled. Some of these things are specific to sprockets support so it may be related.

The readme should say that TheRubyRacer should NOT be used, react does not work on libV8 less than ~v5 and TheRubyRacer is stuck on libV8 ~v3. If you need one, miniracer is the current best.

@AirWick219
Copy link
Author

Thank you so much. Ideally, I would not want include any of javascript runtime gems at all.

@AirWick219
Copy link
Author

Btw ... It works if I don't remove node.js in the dockerfile . It's less than ideal. But at least I don't have to include a extra gem.

@chulkilee
Copy link
Contributor

This is because react-rails always require execjs - see https://github.com/reactjs/react-rails/blob/v2.4.7/lib/react/jsx.rb#L1

@BookOfGreg
Copy link
Member

Nice find @chulkilee . Do you there's a chance for PR to require on first use? Or perhaps with Rails autoloading, we could remove the requires altogether:
https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoloading-and-require
If someone would be willing to take it on, that would be awesome :)

@chulkilee
Copy link
Contributor

I haven't investigated far enough. Even react-rails try to avoid loading execjs, it would need a change to use server side rendering I guess.

@AirWick219 you may use multi stage docker build to include nodejs in build step, and do not include nodejs in runtime. That works for other asset-related gems requiring nodejs (e.g. uglifier) - but not for react-rails.

@BookOfGreg BookOfGreg added the Hacktoberfest https://hacktoberfest.digitalocean.com/ label Oct 1, 2018
@LS80
Copy link

LS80 commented Apr 26, 2019

ENV EXECJS_RUNTIME=Disabled

Is probably what you want

@hopewise
Copy link

When requesting the app, execjs starts and nodejs processes start working for a long time, I am not sure if it actually rebuild the assets at production server??

How can I prevent this? Can you please check here:
https://stackoverflow.com/questions/63895516/why-nodejs-process-starts-when-requesting-rails-app

I tried ENV EXECJS_RUNTIME=Disabled but it did not solve the issue.

@alkesh26
Copy link
Collaborator

@hopewise Closing the issue. Feel free to reopen if you are still facing the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants