Skip to content
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

Look for node before nodejs #81

Closed
vasiliy-pdk opened this issue Sep 24, 2018 · 10 comments
Closed

Look for node before nodejs #81

vasiliy-pdk opened this issue Sep 24, 2018 · 10 comments

Comments

@vasiliy-pdk
Copy link

When using NVM having a system node package installed on Debian or Ubuntu, execjs always uses the system node. This is because it looks for the nodejs binary first, which is provided by the system binary and not NVM (since it is something introduced by the distribution). This happens here:

https://github.com/rails/execjs/blob/master/lib/execjs/runtimes.rb#L21-L24

Suggestion: first look for node, then nodejs. nodejs command is not a standard one, the standard cli command for node invocation is node, according to https://nodejs.org/api/cli.html
Or don't look for nodejs at all (unless an env variable is set).

First brought up in NVM: nvm-sh/nvm#308
Second brought up here sstephenson#197 by @wvengen

@elaine-jackson
Copy link

Is a PR for this issue welcome?

@coding-bunny
Copy link

I've seen the open pull-request to address this problem, but the issue goes further.
I could not get execJS to work on my Linux Mint system, with nodenv installed.
Only after installing nodejs through the package manager I actually got this working.

So even if execJS has support to look for node, on a linux environment it doesn't even get to that point because it throws the exception that no suitable runtime exists when nodejs is not available.

@moubry
Copy link

moubry commented Jan 9, 2019

This is an issue that is affecting me as well using the Heroku multi-buildpack (Node + Ruby) on a base image that already comes with an ancient version of Node installed:

bash-4.3# node -v
v10.15.0
bash-4.3# nodejs -v
v0.10.25

Is there a way to force ExecJS to choose node in this case?

@metaskills
Copy link

That's a good question @moubry. From reading the source, I think something like this might work?

# In config/initializers/execjs
silence_warnings do
  ExecJS::Runtimes.const_set :Node, ExecJS::ExternalRuntime.new(
    name:        "Node.js (V8)",
    command:     ["node"],
    runner_path: ExecJS.root + "/support/node_runner.js",
    encoding:    'UTF-8'
  )
end

@metaskills
Copy link

Or maybe less invasive.... something like this?

# In config/initializers/execjs
ExecJS::Runtimes::Node.instance_variable_set :@command, ['node']

@TurtleTony
Copy link

Any updates on this? I'm thinking of just symlinking the binary for as a temporary workaround but I'd love ExecJS to handle this itself!

@haaayden
Copy link

haaayden commented Jul 17, 2019

I'm still having issues with this on Ubuntu 18 LTS. Get a ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. when I've got node binary available but not the nodejs binary. Using execjs gem with commit hash f6dc08c58ab4e1a467f64d471ee6e0127c2f14de as I noticed there were a few merged PRs (that might've solved the problem) ahead of release version 2.7.0.

$ which node
/usr/local/bin/node
$ node --version
v10.16.0
$ nodejs --version
The program 'nodejs' is currently not installed. To run 'nodejs' please ask your administrator to install the package 'nodejs'

Tried both of metaskills suggestions, they don't seem to solve the issue.

Creating a symlink from the nodejs binary to node does work, but it feels a bit dirty, and is an odd step to add to infrastructure setup:

sudo ln -s "$(which node)" /usr/bin/nodejs

To echo others thoughts, would be nice if ExecJS found node itself, even when nodejs is not present.

@freesteph
Copy link

Hopefully #84 fixes it. Can someone cut a new release?

@aesyondu
Copy link

I'm still having issues with this on Ubuntu 18 LTS. Get a ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. when I've got node binary available but not the nodejs binary. Using execjs gem with commit hash f6dc08c58ab4e1a467f64d471ee6e0127c2f14de as I noticed there were a few merged PRs (that might've solved the problem) ahead of release version 2.7.0.

$ which node
/usr/local/bin/node
$ node --version
v10.16.0
$ nodejs --version
The program 'nodejs' is currently not installed. To run 'nodejs' please ask your administrator to install the package 'nodejs'

Tried both of metaskills suggestions, they don't seem to solve the issue.

Creating a symlink from the nodejs binary to node does work, but it feels a bit dirty, and is an odd step to add to infrastructure setup:

sudo ln -s "$(which node)" /usr/bin/nodejs

To echo others thoughts, would be nice if ExecJS found node itself, even when nodejs is not present.

Can confirm linking works.

/usr/bin/nodejs -> /home/vagrant/.nvm/versions/node/v13.14.0/bin/node

Ubuntu 18.04.5 LTS

rvm 1.29.10
ruby 2.3.1p112
rails (= 4.2.6)
whenever (0.9.7)
execjs-2.7.0

nvm@0.35.2
node@13.14.0

@robin850
Copy link
Member

This should have been fixed with #84.

@byroot byroot closed this as completed May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests