execJs: 'Could not find a JavaScript runtime' but execjs AND therubyracer are in Gemfile

≯℡__Kan透↙ 提交于 2019-11-28 02:48:34
Paul Williams

Ubuntu Users:

I had the same problem and I fixed it by installing nodejson my system independent of the gem.

on ubuntu its: sudo apt-get install nodejs

I'm using 64bit ubuntu 11.10

update: From @Galina 's answer below I'm guessing that the latest version of nodejs is required, so @steve98177 your best option on a redhat(or CentOS) box is to install from source code as @Galina did, but as you can't "make/install" on this box ?, I suggest you try to install a fedora rpm(long shot) https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager or find another RH/CentOs box(that you can 'make' on) and create your own rpm and install on original RH box(if old glibc on RH plays nice).

The real issue here(IMHO) is installing Gems that have dependencies on installed packages outside of the ruby environment, is there a way of knowing before installing ? an RFI for Gems or bundler ?


CentOS/RedHat Users:

sudo yum install nodejs
Tiago

In your gemfile add:

gem 'execjs'
gem 'therubyracer', :platforms => :ruby

For more details: ExecJS and could not find a JavaScript runtime

This is the link I needed to fix the problem (install nodejs): https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

When you create an empty project, this line is commented in Gemfile. Just uncomment it and bundle!

gem 'therubyracer', :platforms => :ruby

I had similar issues on ubuntu 12.04. Installing Node.js fixed it.

I am using Ubuntu 11.10- 32 bit with ruby 1.9.3p194, rails 3.2.3, gem 1.8.24. Was receiving the same Javascript error while running "script/rails console".

However doing a "sudo apt-get install nodejs" solved my issue.

Fedora users WILL NOT be able to do a simple "yum install nodejs" due to serious naming and file placement conflicts that prevent this package from even being available through the Fedora repositories.

There is apparently at least one alternate repository available with an alternate build that may work, but that's two too many "alternates" for me to be willing to use it-- I'm looking for another alternative.

I had the same problem on a staging server. I had no issues running rake tasks on my local development machine, but deploying to the staging server failed with the "Could not find a JavaScript runtime" error message while trying to run the assets:precompile rake task.

Of course, therubyracer and execjs were in my Gemfile, and I was using the latest versions. My Gemfile.lock files matched, and I further verified versions by running bundle show.

After searching around on Google, I ended up deleting all of my gems and reinstalling them which fixed the problem. I still don't know what the root cause was, but maybe this will help you.

Here's what my environment looks like, BTW:

Ubuntu 10.04.3 LTS
rbenv
Ruby 1.9.2-p290
bundler-1.0.21
execjs-1.3.0
therubyracer-0.9.9

I had the same problem. Adding the gems 'execjs' and 'therubyracer' not work for me. apt-get install nodejs - also dosn't works. I'm using 64bit ubuntu 10.04.

But it helped me the following: 1. I created empty folder (for example "java"). 2. From the terminal in folder that I created I do:

$ git clone git://github.com/ry/node.git
$ cd node
$ ./configure
$ make
$ sudo make install

After that I run "bundle install" as usual (from folder with ruby&rails project). And the problem was resolved. Ruby did not have to reinstall.

If you were on ubuntu $ sudo apt-get install nodejs

Try to don't use another systems like Windows to development. Think that almost all servers in the world are Linux servers, so when you try to deploy that application it will be easier if you have developed that on a Linux or Unix environment too.

I had this occur to me on my Windows machine, turns out the problem was quite different. I had accidentally removed some paths from my %PATH% variable. Simply restarting the command prompt solved it. It seems as though there was a JS runtime in one of those missing paths.

I have pulled my hair out with this error a few time. I have managed to make it sometime disappear by restarting Apache/Nginx.

So I fixed it the same way as above, by adding the following to the GEM file:

gem 'execjs'
gem 'therubyracer', :platforms => :ruby

and then I DELETED my gemfile.lock file and then reran "bundle install". I found only then did "bundle install" actually install the correct libraries etc.

kilombo1

On Ubuntu, I had to sudo apt-get update and then the nodejs install worked.

when i generate rails g controller i got the same error. After that when do the following changes on Gemfile(in rails 4) everything went smooth.The changes i made was

gem 'execjs'
gem 'therubyracer', "0.11.4"
After that i can able to run the server and able to do all basic operations on the application.

add in your gemfile which is in the folder you have created: gem 'execjs' gem 'therubyracer'

In my case running the bundle command did the trick. I trust they find each other then.

I had this problem when using RubyMine (6.3.3). One day I tried to run my code, but it didn't work and complained about no JavaScript runtime found. I was able to run rails s though. The fix for me was creating a new Run configuration. Seems really bizarre that the Run configuration would become corrupt.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!