Node.js not found by Rails / execjs - ruby-on-rails

I have node.js installed by compiling and installing it from the root user. I think this maybe where the hangup is. From the user running the rails app I checked for node.js.
$ which node
/usr/local/bin/node
When I launched my rails app (Rails 3.2.9) I get the universally unhelpful "We're sorry, but something went wrong." Checking the the production error log I saw that the Javascript runtime was not found. That's confusing as it is obviously installed. So I went about forcing the Node javascript runtime. I edited config/boot.rb to include:
ENV['EXECJS_RUNTIME'] = 'Node'
I checked my app again, while watching the production log. This time I got the error
ActionView::Template::Error (Node.js (V8) runtime is not available on this system
Still confused. I went to the execjs gem and changed the runtime command to the exact installed path.
Node = ExternalRuntime.new(
:name => "Node.js (V8)",
:command => "/usr/local/bin/node",
:runner_path => ExecJS.root + "/support/node_runner.js",
:encoding => 'UTF-8'
)
I still get the same error. Node is installed and accessible by the user but the gem/rails can't seem to use it.
The server is run CentOS 6.3. The specific javascript file causing the error to be thrown is jquery.nivo.slider.pack.js. Which I didn't edit after downloading it from nivo.

So, I have Ruby 2.0.0 installed and Rails 4.0.2 on CentOS 5.10 using Apache2 with Passenger. My first step I tried was opening the rails console and typing in the following command:
ExecJS.runtime
It returned the following value:
#<ExecJS::ExternalRuntime:0x99ab380 #name="Node.js (V8)", #command=["nodejs", "node"],#runner_path="/home/foo/vendor/bundle/ruby/2.0.0/gems/execjs-2.1.0
/lib/execjs/support/node_runner.js", #encoding="UTF-8", #deprecated=false, #binary="node">
Which meant that node was indeed installed and detected, but for some reason it was not working.
So, I tried the example on the website:
ExecJS.eval("'red yellow blue'.split(' ')")
and I got the correct response. So, now I am wondering why Passenger isn't picking it up.
Then, I noticed that passenger shows the path variable and it looks like:
/home/foo/vendor/bundle/ruby/2.0.0/bin:/usr/local/rvm/gems/ruby-2.0.0-p481/bin:/usr/local/rvm/gems/ruby-2.0.0-p481#global/bin:/usr/local/rvm/rubies/ruby-2.0.0-p481/bin:/usr/kerberos/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/rvm/bin:/home/foo/bin
But, it seems to be missing the usr/local/bin. I'm no expert on Linux, so for me the easiest way to fix this is with a symbolic link. So, I execute ln -s /usr/local/bin/node /usr/bin/node. You may want to note that I found the path to my nodejs using the command find / -name node.
I then refreshed my web application and wouldn't you know it worked. So, if it worked for me I am hoping that it can help someone else out.
UPDATE (Probably Better Way): This is probably a better way to do it. We can compile it from source like so:
mkdir ~/install
cd ~/install
wget https://nodejs.org/dist/v7.2.1/node-v7.2.1.tar.gz
tar xvf node-v7.2.1.tar.gz
cd node-v7.2.1
./configure --prefix=/usr/
make && make install
This way Node.js will be installed in the path where Passenger expects it to be.

I have had similar issue installing nodejs with source on my centos 6.3 system. It was successfully installed but I keep failing in compiling my ror app assets until I explicitly set the PATH to where it was installed (nodejs)
[root]# make install
...
installing /usr/local/lib/node_modules/npm/html/doc/folders.html
symlinking ../lib/node_modules/npm/bin/npm-cli.js -> /usr/local/bin/npm
updating shebang of /usr/local/bin/npm to /usr/local/bin/node
[root]# export PATH=/usr/local/bin:$PATH
Now it works. Hope that helps!

I don't know if this will help but check your $PATH that node is in there. Also, you should be using rvm if you want to use node. Check that your node install is done correctly.

Related

Snowflake on Heroku Via ODBC

Update - I got it working by using Sequel and Ruby-ODBC gems and a different build pack for Heroku (https://elements.heroku.com/buildpacks/daasity/heroku-buildpack-snowflake-odbc)
Had to amend the AptFile line
https://sfc-repo.snowflakecomputing.com/odbc/linux/2.18.3/snowflake-odbc-2.18.3.x86_64.deb
to
https://sfc-repo.snowflakecomputing.com/odbc/linux/latest/snowflake-odbc-2.21.0.x86_64.deb
I am looking for some advice to help resolve an issue I am having trying connect a Rails 5.1 app to a Snowflake database via ODBC on Heroku.
I have tried various methods but keep hitting different issues.
Steps taken so far:
Added heroku-community/apt buildpack
Created AptFile with the below packages:
unixodbc
unixodbc-dev
https://raw.githubusercontent.com/carwow/heroku-buildpack-snowflake-odbc/master/snowflake-odbc.deb
Added odbc_adapter gem (https://github.com/localytics/odbc_adapter)
Modified my database.yml file to include :snowflake connection details.
Created a new class to mirror a table held in Snowflake, added a line to establish_connection to snowflake and a method to test the connection.
When I run this locally, everything works perfectly. When I deploy to Heroku and try to run the same method I get this error:
ODBC::Error: S1000 (-1) [unixODBC][DSI] The error message SFRestRequestFailed could not be found in the en-US locale. Check that /app/.apt/usr/lib/snowflake/odbc/lib/SFMessages_en-US.xml exists.
When I check the file structure on Heroku, I can see that SFMessages_en_US.xml is in a different path.
I tried using isql -v to see if I could get more details but that returns an error:
[28000][unixODBC][DSI] The error message DSIReqSettingNotFound could not be found in the en-US locale. Check that /app/.apt/usr/lib/snowflake/odbc/lib/ODBCMessages_en-US.xml exists.
I've been trying to get this to work but without being able to see the underlying error I am stuck.
Try adding the following (copied from Dockerfile, so you need to change that to match Heroku) before installing SNFLK ODBC drivers:
ENV LANGUAGE=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
RUN apt-get install locales && locale-gen

How does one make sure that their rails environment on one machine is the same as another?

I have three macs. I have a rails app, that I can run on two of them. On the third, I can create a new rails app and it works fine and some of my other rails apps from the other machines work fine, however the one that I need to have work on the one machine always gives me a message about not being able to find an image:
/Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': dlopen(/Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /usr/local/opt/mysql/lib/libmysqlclient.21.dylib
Reason: image not found - /Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
I have followed suggestions about installing the mysql2 bundle using:
gem install mysql2 -v '0.5.3' -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"
then bundle install, and it says all is fine. Yet 'rails s' produces that unable to find image message.
I use rbenv to manage versions and on all machines ruby is 2.6.3 and rails is 5.2.4.
What other aspects of the configuration of the app do I need to check to make sure they are the same? I have a script called 'laptop' that I obtained using:
cd ~
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/mac
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/Brewfile
/usr/bin/env bash mac 2>&1 | tee ~/laptop.log
I run this on each machine when I am setting up to install or run a rails app. On the problem machine I do get messages like:
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python#2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
during the laptop run, but at the end it says all modules were installed correctly. I have a feeling that's not really true and may be part of the problem. If so, what is causing this? I'm running OS X 10.14.6 on the machine in question.
I also notice that libssl.1.0.0.dylib is NOT present at the specified location. How do I install this and moreover, how to I make sure that all of these pieces are properly coordinated?
Found it finally! Thank you:
https://rorguide.blogspot.com/2011/07/getting-error-library-not-loaded.html
I had looked at a lot of these and tried the making a soft link to no effect, but this was the first time I found this one!:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
worked!

node version on $PATH issue on mac

Having problems when trying to push my Rails 5.1 app to Heroku. rake:assets:precompile fails with
Webpacker requires Node.js >= 6.0.0 and you are using 0.10.30
I've posted before on this but haven't been able to resolve it, and am now going round in circles. I'm told it looks like an issue with my $PATH and I need to make sure that /usr/local/bin is in my $PATH. It looks like it is. I can also run node and print from the console. I can also see the version of node I'm running, so I'm now at a loss. One thing that does look obviously wrong, is that amount of 'stuff' in the $PATH. Could this be causing the issue?
Simons-MBP:~ Simon$ echo $PATH
/Users/Simon/.rvm/gems/ruby-2.4.0/bin:/Users/Simon/.rvm/gems/ruby-2.4.0#global/bin:/Users/Simon/.rvm/rubies/ruby-2.4.0/bin:/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/Simon/.rvm/bin
Simons-MBP:~ Simon$ node
> console.log('hello node')
hello node
undefined
>
(To exit, press ^C again or type .exit)
>
Simons-MBP:~ Simon$ node -v
v8.9.4
I don't believe the error is because of your local version of Node, but the Node version on Heroku.
See how to specify your Node Engine on Heroku's blog
If that doesn't work, you may need to specify a Buildpack(one compatible with both Ruby & Node), however, I believe you may only need to specify the engine.

rails s command does not run from ssh

I am using Putty to connect to my localhost, and I don't have any problems apparently, however, when I run command rails s to start my rails 4.0.0 application from Putty, it gives me this message:
jose#jose-laptop:~/rails/dedicated-agenda$ rails s
The program 'rails' can be found in the following packages:
ruby-railties-3.2
ruby-railties-4.0
Try: sudo apt-get install
I don't get that message from the terminal though, the application starts running just fine.
I had to reinstall ubuntu so I upgraded to ubuntu 14.04 just in case you need to know.
I don't know if I am missing something in my ssh settings or how could I use rails s from Putty.
Thanks in advance.
Your PATH environment variable is set differently when you are executing programs in an interactive shell and by ssh(using putty).
Use absolute path of the program to not depend on the PATH variable.
You can also set the right PATH variable at ~/.profile file and load the updated variables using the command source ~/.profile.
Now, you should be able to run the command.
You can use the command
>which rails
to see where rails is installed on your working session.
Then you need to make sure that is in your path when you ssh in.
If you are ssh'ing in as a different use then that user may not have permission to see the rails executable.

ruby script/plugin discover RuntimeError [duplicate]

The firewall I'm behind is running Microsoft ISA server in NTLM-only mode. Hash anyone have success getting their Ruby gems to install/update via Ruby SSPI gem or other method?
... or am I just being lazy?
Note: rubysspi-1.2.4 does not work.
This also works for "igem", part of the IronRuby project
For the Windows OS, I used Fiddler to work around the issue.
Install/Run Fiddler from www.fiddler2.com
Run gem:
$ gem install --http-proxy http://localhost:8888 $gem_name
I wasn't able to get mine working from the command-line switch but I have been able to do it just by setting my HTTP_PROXY environment variable. (Note that case seems to be important). I have a batch file that has a line like this in it:
SET HTTP_PROXY=http://%USER%:%PASSWORD%#%SERVER%:%PORT%
I set the four referenced variables before I get to this line obviously. As an example if my username is "wolfbyte", my password is "secret" and my proxy is called "pigsy" and operates on port 8080:
SET HTTP_PROXY=http://wolfbyte:secret#pigsy:8080
You might want to be careful how you manage that because it stores your password in plain text in the machine's session but I don't think it should be too much of an issue.
This totally worked:
gem install --http-proxy http://COMPANY.PROXY.ADDRESS $gem_name
I've been using cntlm (http://cntlm.sourceforge.net/) at work. Configuration is very similar to ntlmaps.
gem install --http-proxy http://localhost:3128 _name_of_gem_
Works great, and also allows me to connect my Ubuntu box to the ISA proxy.
Check out http://cntlm.wiki.sourceforge.net/ for more information
I tried some of these solutions, and none of them worked. I finally found a solution that works for me:
gem install -p http://proxy_ip:proxy_port rails
using the -p parameter to pass the proxy. I'm using Gem version 1.9.1.
Create a .gemrc file (either in /etc/gemrc or ~/.gemrc or for example with chef gem in /opt/chef/embedded/etc/gemrc) containing:
http_proxy: http://proxy:3128
Then you can gem install as usual.
This solved my problem perfectly:
gem install -p http://proxy_ip:proxy_port compass
You might need to add your user name and password to it:
gem install -p http://[username]:[password]#proxy_ip:proxy_port compass
If you are having problems getting authenticated through your proxy, be sure to set the environment variables in exactly the format below:
set HTTP_PROXY=some.proxy.com
set HTTP_PROXY_USER=user
set HTTP_PROXY_PASS=password
The user:password# syntax doesn't seem to work and there are also some badly named environment variables floating around on Stack Overflow and various forum posts.
Also be aware that it can take a while for your gems to start downloading. At first I thought it wasn't working but with a bit of patience they started downloading as expected.
Quick answer : Add proxy configuration with parameter for both install/update
gem install --http-proxy http://host:port/ package_name
gem update --http-proxy http://host:port/ package_name
I tried all the above solutions, however none of them worked. If you're on linux/macOS i highly suggest using tsocks over an ssh tunnel. What you need in order to get this setup working is a machine where you can log in via ssh, and in addition to that a programm called tsocks installed.
The idea here is to create a dynamic tunnel via SSH (a socks5 proxy). We then configure tsocks to use this tunnel and to start our applications, in this case:
tsocks gem install ...
or to account for rails 3.0:
tsocks bundle install
A more detailed guide can be found under:
http://blog.byscripts.info/2011/04/bypass-a-proxy-with-ssh-tunnel-and-tsocks-under-ubuntu/
Despite being written for Ubuntu the procedure should be applicable for all Unix based machines. An alternative to tsocks for Windows is FreeCap (http://www.freecap.ru/eng/). A viable SSH client on windows is called putty.
Posts abound regarding this topic, and to help others save hours of trying different solutions, here is the final result of my hours of tinkering.
The three solutions around the internet at the moment are:
rubysspi
apserver
cntlm
rubysspi only works from a Windows machine, AFAIK, as it relies on the Win32Api library. So if you are on a Windows box trying to run through a proxy, this is the solution for you. If you are on a Linux distro, you're out of luck.
apserver seems to be a dead project. The link listed in the posts I've seen lead to 404 page on sourceforge. I search for "apserver" on sourceforge returns nothing.
The sourceforge link for cntlm that I've seen redirects to http://cntlm.awk.cz/, but that times out. A search on sourceforge turns up this link, which does work: http://sourceforge.net/projects/cntlm/
After downloading and configuring cntlm I have managed to install a gem through the proxy, so this seems to be the best solution for Linux distros.
A workaround is to install http://web.archive.org/web/20060913093359/http://apserver.sourceforge.net:80/ on your local machine, configure it and run gems through this proxy.
Install: Just download apserver 097 (and not the experimental 098!) and unpack.
Configure: Edit the server.cfg file and put the values for your MS proxy in PARENT_PROXY and PARENT_PROXY_PORT. Enter the values for DOMAIN and USER. Leave PASSWORD blank (nothing after the colon) – you will be prompted when launching it.
Run apserver: cd aps097; python main.py
Run Gems: gem install—http-proxy http://localhost:5865/ library
I am working behind a proxy and just installed SASS by downloading directly from http://rubygems.org.
I then ran sudo gem install [path/to/downloaded/gem/file]. I cannot say this will work for all gems, but it may help some people.
This worked for me in a Windows box:
set HTTP_PROXY=http://server:port
set HTTP_PROXY_USER=username
set HTTP_PROXY_PASS=userparssword
set HTTPS_PROXY=http://server:port
set HTTPS_PROXY_USER=username
set HTTPS_PROXY_PASS=userpassword
I have a batch file with these lines that I use to set environment values when I need it.
The trick, in my case, was HTTPS_PROXY sets. Without them, I always got a 407 proxy authentication error.
If you are on a *nix system, use this:
export http_proxy=http://${proxy.host}:${port}
export https_proxy=http://${proxy.host}:${port}
and then try:
gem install ${gem_name}
rubysspi-1.3.1 worked for me on Windows 7, using the instructions from this page:
http://www.stuartellis.eu/articles/installing-ruby/
If you want to use SOCKS5 proxy, you may try rubygems-socksproxy https://github.com/gussan/rubygems-socksproxy.
It works for me on OSX 10.9.3.
If behind a proxy, you can navigate to Ruby downloads, click on Download, which will download the specified update ( or Gem ) to a desired location.
Next, via Ruby command line, navigate to the downloaded location by using : pushd [directory]
eg : pushd D:\Setups
then run the following command: gem install [update name] --local
eg: gem install rubygems-update --local.
Tested on Windows 7 with Ruby update version 2.4.1.
To check use following command : ruby -v
Rather than editing batch files (which you may have to do for other Ruby gems, e.g. Bundler), it's probably better to do this once, and do it properly.
On Windows, behind my corporate proxy, all I had to do was add the HTTP_PROXY environment variable to my system.
Start -> right click Computer -> Properties
Choose "Advanced System Settings"
Click Advanced -> Environment Variables
Create a new System variable named "HTTP_PROXY", and set the Value to your proxy server
Reboot or log out and back in again
Depending on your authentication requirements, the HTTP_PROXY value can be as simple as:
http://proxy-server-name
Or more complex as others have pointed out
http://username:password#proxy-server-name:port-number
for anyone tunnelling with SSH; you can create a version of the gem command that uses SOCKS proxy:
Install socksify with gem install socksify (you'll need to be able to do this step without proxy, at least)
Copy your existing gem exe
cp $(command which gem) /usr/local/bin/proxy_gem
Open it in your favourite editor and add this at the top (after the shebang)
require 'socksify'
if ENV['SOCKS_PROXY']
require 'socksify'
host, port = ENV['SOCKS_PROXY'].split(':')
TCPSocket.socks_server = host || 'localhost'
TCPSocket.socks_port = port.to_i || 1080
end
Set up your tunnel
ssh -D 8123 -f -C -q -N user#proxy
Run your gem command with proxy_gem
SOCKS_PROXY=localhost:8123 proxy_gem push mygem

Resources