Rails/Passenger/Node.js: ExecJS “Could not find a JavaScript runtime”

半世苍凉 提交于 2019-12-05 00:12:46

I had this problem too. This is what fixed it for me. I added this to the top of my nginx.conf

env PATH;

http://wiki.nginx.org/CoreModule#env

As I zeroed in on this solution I also found this post which helped me start barking up the right tree: https://forums.freebsd.org/viewtopic.php?&t=35539 -- he edits the execjs code to give an absolute path to node. This worked and helped me find out how to give the path to passenger.

So, I found the issue.

First, my installation of Node was not for all users. That said, it was installed and available for the user that Nginx was supposed to be run as. Still, you need to remember to have this in your nginx.conf:

user  ec2-user;
...

http {
    passenger_root /usr/local/rvm/gems/ruby-2.1.0/gems/passenger-4.0.42;
    passenger_ruby /usr/local/rvm/gems/ruby-2.1.0/wrappers/ruby;
    passenger_nodejs /usr/local/bin/node;
    passenger_default_user ec2-user;
...

Second, you also need to make the path to Node available for non-login shells, ie add it to /etc/bashrc and export.

Your environment may be different, but this is the gist.

Spoke too soon in my above comment. Things were working fine on my Hello World Rails app (4.1, with the default Gemfile and config), I stopped the EC2 instance to snapshot it, then upon reboot, I ran into that Exec.js error despite node (~ 0.11) being installed at /usr/local/bin

However, I edited my `/etc/sudoers/ file from

Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin

to:

Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

I restarted the server and Apache and things were working as expected.

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