ExecJS 找不到 JavaScript 运行时

发布于 2024-11-14 06:27:26 字数 724 浏览 1 评论 0原文

我正在尝试使用 Mongoid / Devise Rails 3.1 模板 (Mongoid设计),我不断收到错误消息,指出 ExecJS 无法找到 JavaScript 运行时。当我没有安装任何东西时,这很公平,但我尝试安装 Node.jsMustangRuby Racer,但没有任何效果。

我找不到 JavaScript 运行时。请参阅 sstephenson/ExecJS (GitHub) 以获取可用运行时的列表 (ExecJS::RuntimeUnavailable)。

我需要做什么才能使其正常工作?

I'm trying to use the Mongoid / Devise Rails 3.1 template (Mongoid and Devise), and I keep getting an error stating ExecJS cannot find a JavaScript runtime. Fair enough when I didn't have any installed, but I've tried installing Node.js, Mustang and the Ruby Racer, but nothing is working.

I could not find a JavaScript runtime. See sstephenson/ExecJS (GitHub) for a list of available runtimes (ExecJS::RuntimeUnavailable).

What do I need to do to get this working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

浊酒尽余欢 2024-11-21 06:27:26

Ubuntu 用户

我使用的是 Ubuntu 11.04,也遇到了类似的问题。 安装 Node.js 修复了它。

从 Ubuntu 13.04 x64 开始,您只需运行:

sudo apt-get install nodejs

这将解决问题。


CentOS/RedHat 用户

sudo yum install nodejs

Ubuntu Users

I'm on Ubuntu 11.04 and had similar issues. Installing Node.js fixed it.

As of Ubuntu 13.04 x64 you only need to run:

sudo apt-get install nodejs

This will solve the problem.


CentOS/RedHat Users

sudo yum install nodejs
心头的小情儿 2024-11-21 06:27:26

只需添加 ExecJSRuby Racer 在您的 gem 文件中,然后运行 ​​bundle install

gem 'execjs'

gem 'therubyracer'

之后一切都应该好起来。

Just add ExecJS and the Ruby Racer in your gem file and run bundle install after.

gem 'execjs'

gem 'therubyracer'

Everything should be fine after.

安稳善良 2024-11-21 06:27:26

在你的 Gem 文件中,编写

gem 'execjs'
gem 'therubyracer'

然后运行

bundle install

一切对我来说都很好:)

In your Gem file, write

gem 'execjs'
gem 'therubyracer'

and then run

bundle install

Everything works fine for me :)

生来就爱笑 2024-11-21 06:27:26

我遇到了类似的问题:我的 Rails 3.1 应用程序在 Windows 上运行良好,但在 Linux 上运行时出现与 OP 相同的错误。在这两个平台上对我有效的修复是将以下内容添加到我的 Gemfile 中:

gem 'therubyracer', :platforms => :ruby

诀窍是知道 :platforms =>; :ruby 实际上意味着仅将此 gem 与“C Ruby (MRI) 或 Rubinius,但不适用于 Windows。”

中描述了 :platforms 的其他可能值bundler 手册页

仅供参考:Windows 有一个内置的 JavaScript 引擎,execjs 可以找到它。在 Linux 上,虽然有几个可以安装的内置程序,但没有内置程序。 therubyracer 就是其中之一。其他列在 execjs README.md。

I had a similar problem: my Rails 3.1 app worked fine on Windows but got the same error as the OP when running on Linux. The fix that worked for me on both platforms was to add the following to my Gemfile:

gem 'therubyracer', :platforms => :ruby

The trick is knowing that :platforms => :ruby actually means only use this gem with "C Ruby (MRI) or Rubinius, but NOT Windows."

Other possible values for :platforms are described in the bundler man page.

FYI: Windows has a builtin JavaScript engine which execjs can locate. On Linux there is not a builtin although there are several available that one can install. therubyracer is one of them. Others are listed in the execjs README.md.

可爱咩 2024-11-21 06:27:26

将以下 gem 添加到我的 Gemfile 解决了问题:

gem 'therubyracer'

然后捆绑新的依赖项:

$ bundle install

Adding the following gem to my Gemfile solved the issue:

gem 'therubyracer'

Then bundle your new dependencies:

$ bundle install
冷…雨湿花 2024-11-21 06:27:26

另一种方法是只捆绑而不包含包含您没有的东西的宝石组。

这样做:

bundle install --without assets

您根本不必修改 Gemfile,当然前提是您不做资产链的事情 - 这通常适用于非开发环境。 Bundle 将记住您在 .bundle/config 文件中的“--without”设置。

An alternative way is to just bundle without the gem group that contains the things you don't have.

So do:

bundle install --without assets

you don't have to modify the Gemfile at all, providing of course you are not doing asset chain stuff - which usually applies in non-development environments. Bundle will remember your '--without' setting in the .bundle/config file.

嗳卜坏 2024-11-21 06:27:26

在您的 gem 文件中添加以下 gem

gem 'therubyracer'
gem 'execjs'

并运行

bundle install

您就完成了:)

Add following gems in your gem file

gem 'therubyracer'
gem 'execjs'

and run

bundle install

you are done :)

等你爱我 2024-11-21 06:27:26

对于亚马逊 Linux(AMI):

sudo yum install nodejs npm --enablerepo=epel

For amazon linux(AMI):

sudo yum install nodejs npm --enablerepo=epel
情徒 2024-11-21 06:27:26

我遇到了同样的错误,但仅在我的临时服务器上,而不是在我的生产环境上。两个环境中都已经安装了nodejs。

通过输入:

which node

我发现节点命令位于:生产时的 /usr/bin/node
但是: /usr/local/bin/node 处于暂存状态。

在登台上创建符号链接后,即:

sudo ln -s /usr/local/bin/node /usr/bin/node

应用程序然后在登台中工作。

没有混乱没有大惊小怪。

I had this same error but only on my staging server not my production environment. nodejs was already installed on both environments.

By typing:

which node

I found out that the node command was located in: /usr/bin/node on production
but: /usr/local/bin/node in staging.

After creating a symlink on staging i.e. :

sudo ln -s /usr/local/bin/node /usr/bin/node

the application then worked in staging.

No muss no fuss.

眼眸印温柔 2024-11-21 06:27:26

我通过 nvm 安装了 node 并在使用 Capistrano 部署时遇到了此问题。 Capistrano 不会自动加载 nvm,因为它以非交互方式运行。

要修复此问题,只需将 nvm 添加到 ~/.bashrc 的行移至顶部即可。该文件将如下所示:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

I installed node via nvm and encountered this issue when deploying with Capistrano. Capistrano didn't load nvm automatically because it runs non-interactively.

To fix, simply move the lines that nvm adds to your ~/.bashrc up to the top. The file will then look something like this:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac
薄荷港 2024-11-21 06:27:26

我曾经将 Ruby Racer 添加到 Gem 文件中来修复它。但是,嘿,Node.js 可以工作!

I used to add the Ruby Racer to the Gem file to fix it. But hey, Node.js works!

想你的星星会说话 2024-11-21 06:27:26

不要使用 RubyRacer,因为它对内存不好。按照这里一些人的建议安装 Node.js 是一个更好的主意。

ExecJs 库可以使用的可用运行时列表还记录了 Node.js

https://github 的使用。 com/sstephenson/execjs

因此,Node.js 并不是一种矫枉过正的解决方案,而且比使用 RubyRacer 更好。

Don't Use RubyRacer as it is bad on memory. Installing Node.js as suggested by some people here is a better idea.

This list of available runtimes that can be used by ExecJs Library also documents the use of Node.js

https://github.com/sstephenson/execjs

So, Node.js is not an overkill, and much better solution than using the RubyRacer.

做个ˇ局外人 2024-11-21 06:27:26

仅供参考,这解决了我的问题......这是一个路径问题:
http://forums.freebsd.org/showthread.php?t=35539

FYI, this fixed the problem for me... it's a pathing problem:
http://forums.freebsd.org/showthread.php?t=35539

野生奥特曼 2024-11-21 06:27:26

我遇到了这个问题,大多数答案都承认了这个问题,但我想提供我无法找到的明确答案。

问题

此问题发生在我的服务器 (vps) 上,因为我使用 nvm 安装了节点,并且如果您使用,此节点版本管理器会加载到 shell 配置文件(例如 .bashrc)中如果您使用 zsh,则 bash 或在 .zshrc 内。

当您加载 shell 配置文件(在 shell 启动时自动)时,会发生什么情况:$PATH 变量被 nvm 路径丰富,这样 < code>node 是可以找到的。这很重要,因为放在 PATH 变量中的所有路径都是 shell 查找命令的位置。

问题的要点

由于 Capistrano 是一个通过 ssh 运行的非交互式命令工具,我不认为 zshrc 以及 nvmnode 已加载。因此,即使已安装,在 capistrano 部署期间也找不到 node 命令。

我的解决方案

为了使节点可找到,我发现最简单的解决方案是将已安装的 node 版本放入原始 $PATH 中(即使不加载 .zshrc< , $PATH 也可用) /代码>)。这样做的好地方是 /usr/bin/

第 1 步:查找节点当前在哪里

因此找到您的节点安装在哪里:

which node
# /home/deploy/.nvm/versions/node/v16.15.1/bin/node

或者

whereis node
# node: /home/deploy/.nvm/versions/node/v16.15.1/bin/node
第 2 步:创建符号链接

现在在 /usr/bin 中创建一个软链接

ln -s /home/deploy/.nvm/versions/node/v16.15.1/bin/node /usr/bin/
第 3 步:验证符号链接

现在如果您再次运行 < code>whereis node 它应该打印两个路径。

whereis node
node: /usr/bin/node /home/deploy/.nvm/versions/node/v16.15.1/bin/node

如果您现在运行 capistrano,它应该可以正常工作而不会抛出 execjs 错误。

如何更新

如果您在项目的整个生命周期中更新已安装的 node 版本,您需要记住删除您创建的符号链接并使用安装的新 node 版本重新安装它。

我不会做的事情

  • 如果没有 node 版本管理器,我不会直接在服务器上安装节点。
  • 我不会修改 execjs 内的代码,因为该库工作正常,
  • 我不会使用 therubyracer 在 ruby​​ 中运行 v8,这只会增加不必要的开销。

这些只是解决方法,不理解和承认我上面解释的主要问题。

其他原因

当然,如果您使用nvm安装了node(建议使用nvm,但超出了本问题的范围),并且capistrano仍然找不到node,则此问题和解决方案是相关的。

但是,可能还有其他人提到的其他问题,例如根本没有安装 node,或者没有安装 execjs gem。

I had this issue and mostly there are answers that acknowledge the issue but I wanted to contribute with the clear answer I wasn't able to find.

The issue

This issue happened on my server (vps) because I installed node with nvm and this node version manager is loaded in the shell configuration file such as .bashrc if you use bash or inside .zshrc if you use zsh.

What happens when you load the shell configuration file (automatically at startup time of the shell) is that the $PATH variable, is enriched with the nvm path, such that also node is findable. This is important, because all the paths put inside the PATH variable is where the shell looks for commands.

Main point of the issue

Since Capistrano is a non-interactive command tool that runs via ssh, I don't think zshrc and hence nvm and hence node are loaded. Therefore the node command wouldn't be findable during capistrano deployment, even if it's installed.

My solution

In order to make node findable, I found the easiest solution to be to put the installed node version inside the original $PATH (that being the $PATH avaiable even without loading .zshrc). A good place to do that is /usr/bin/.

Step 1: find where is node currently

Therefore find where is your node installed:

which node
# /home/deploy/.nvm/versions/node/v16.15.1/bin/node

or

whereis node
# node: /home/deploy/.nvm/versions/node/v16.15.1/bin/node
Step 2: create symlink

Now create a soft link in /usr/bin

ln -s /home/deploy/.nvm/versions/node/v16.15.1/bin/node /usr/bin/
Step 3: verify symlink

Now if you run again whereis node it should print both paths.

whereis node
node: /usr/bin/node /home/deploy/.nvm/versions/node/v16.15.1/bin/node

If you run capistrano now, it should work without throwing execjs error.

How to update

if you update the installed node version throughout the lifetime of the project you need to remember to delete the symlink you created and reinstall it with the new node version installed.

Things I wouldn't do

  • I would not install directly node on the server without a node version manager.
  • I would not modify the code inside execjs because that library is working correctly
  • I would not run v8 in ruby with therubyracer, which just adds unnecessary overhead.

These are just workarounds that do not understand and acknowledge the main issue, which I explained above.

Other reasons

Of course, this issue and solution are relevant if you have installed node with nvm (it's advisable to use nvm but beyond the scope of this question), and capistrano still doesn't find node.

However, there could be other issues as mentioned by others such as that node is not at all installed, or execjs gem is not installed.

依 靠 2024-11-21 06:27:26

2022 年 Mac 上的答案很简单:

brew install nodejs

然后重新运行rails server

The answer on a Mac in 2022 is simply:

brew install nodejs

Then rerun rails server.

万劫不复 2024-11-21 06:27:26

当我开始在 Ruby 1.9.3 中使用 rbenv 时,我开始遇到这个问题,因为我的系统 ruby​​ 是 1.8.7。 gem 安装在两个地方,但由于某种原因,rails 脚本没有选择它。但是将“execjs”和“therubyracer”添加到 Gemfile 中就成功了。

I started getting this problem when I started using rbenv with Ruby 1.9.3 where as my system ruby is 1.8.7. The gem is installed in both places but for some reason the rails script didn't pick it up. But adding the "execjs" and "therubyracer" to the Gemfile did the trick.

执着的年纪 2024-11-21 06:27:26

在你的 gem 文件中
取消注释该行。

19 # gem 'therubyracer', 平台: :ruby

并运行
捆绑安装

您已准备好开始工作。 :)

In your gem file
Uncomment this line.

19 # gem 'therubyracer', platforms: :ruby

And run
bundle install

You are ready to work. :)

旧街凉风 2024-11-21 06:27:26

尝试使用 Ubuntu 18.04、Ruby 2.6.*、Rails 5 等在 RubyMine 中进行调试RubyMine 2019.1.1,我遇到了同样的问题。

为了解决该问题,我取消了 Gemfilemini_racer 行的注释,然后运行 ​​bundle

# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

更改为:

# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'mini_racer', platforms: :ruby

Attempting to debug in RubyMine using Ubuntu 18.04, Ruby 2.6.*, Rails 5, & RubyMine 2019.1.1, I ran into the same issue.

To resolve the issue, I uncommented the mini_racer line from my Gemfile and then ran bundle:

# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

Change to:

# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'mini_racer', platforms: :ruby
内心激荡 2024-11-21 06:27:26

我正在使用 Rails 7 和 bootstrap 5.2.3 Gem。在生产环境中,它在基于 Alpine Linux 的 Docker 容器中运行。就我而言,安装 Nodejs 和 npm 是不够的。我必须像这样安装纱线:

apk add --no-cache yarn

只有在那之后,错误消息才在生产中消失。

I'm using Rails 7 and the bootstrap 5.2.3 Gem. On production it runs in a Docker Container, based on Alpine Linux. For my case it was not enough to install nodejs and npm. I had to install yarn like this:

apk add --no-cache yarn

Only after that, the error message disappeared on production.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文