ExecJS 找不到 JavaScript 运行时
我正在尝试使用 Mongoid / Devise Rails 3.1 模板 (Mongoid 和设计),我不断收到错误消息,指出 ExecJS 无法找到 JavaScript 运行时。当我没有安装任何东西时,这很公平,但我尝试安装 Node.js,Mustang 和 Ruby 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
Ubuntu 用户
我使用的是 Ubuntu 11.04,也遇到了类似的问题。 安装 Node.js 修复了它。
从 Ubuntu 13.04 x64 开始,您只需运行:
这将解决问题。
CentOS/RedHat 用户
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:
This will solve the problem.
CentOS/RedHat Users
只需添加 ExecJS 和 Ruby Racer 在您的 gem 文件中,然后运行
bundle install
。之后一切都应该好起来。
Just add ExecJS and the Ruby Racer in your gem file and run
bundle install
after.Everything should be fine after.
在你的 Gem 文件中,编写
然后运行
一切对我来说都很好:)
In your Gem file, write
and then run
Everything works fine for me :)
我遇到了类似的问题:我的 Rails 3.1 应用程序在 Windows 上运行良好,但在 Linux 上运行时出现与 OP 相同的错误。在这两个平台上对我有效的修复是将以下内容添加到我的
Gemfile
中:诀窍是知道
: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
: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 thebundler
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 theexecjs
README.md.将以下 gem 添加到我的 Gemfile 解决了问题:
然后捆绑新的依赖项:
Adding the following gem to my Gemfile solved the issue:
Then bundle your new dependencies:
另一种方法是只捆绑而不包含包含您没有的东西的宝石组。
这样做:
您根本不必修改 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:
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.
在您的 gem 文件中添加以下 gem
并运行
您就完成了:)
Add following gems in your gem file
and run
you are done :)
对于亚马逊 Linux(AMI):
For amazon linux(AMI):
我遇到了同样的错误,但仅在我的临时服务器上,而不是在我的生产环境上。两个环境中都已经安装了nodejs。
通过输入:
我发现节点命令位于:生产时的 /usr/bin/node
但是: /usr/local/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:
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. :
the application then worked in staging.
No muss no fuss.
我通过 nvm 安装了
node
并在使用 Capistrano 部署时遇到了此问题。 Capistrano 不会自动加载 nvm,因为它以非交互方式运行。要修复此问题,只需将 nvm 添加到
~/.bashrc
的行移至顶部即可。该文件将如下所示: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:我曾经将 Ruby Racer 添加到 Gem 文件中来修复它。但是,嘿,Node.js 可以工作!
I used to add the Ruby Racer to the Gem file to fix it. But hey, Node.js works!
不要使用 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.
仅供参考,这解决了我的问题......这是一个路径问题:
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
我遇到了这个问题,大多数答案都承认了这个问题,但我想提供我无法找到的明确答案。
问题
此问题发生在我的服务器 (vps) 上,因为我使用
nvm
安装了节点,并且如果您使用,此节点版本管理器会加载到 shell 配置文件(例如.bashrc
)中如果您使用zsh
,则bash
或在.zshrc
内。当您加载 shell 配置文件(在 shell 启动时自动)时,会发生什么情况:
$PATH
变量被nvm
路径丰富,这样 < code>node 是可以找到的。这很重要,因为放在PATH
变量中的所有路径都是 shell 查找命令的位置。问题的要点
由于 Capistrano 是一个通过 ssh 运行的非交互式命令工具,我不认为
zshrc
以及nvm
和node 已加载。因此,即使已安装,在 capistrano 部署期间也找不到
node
命令。我的解决方案
为了使节点可找到,我发现最简单的解决方案是将已安装的
node
版本放入原始 $PATH 中(即使不加载.zshrc< , $PATH 也可用) /代码>)。这样做的好地方是
/usr/bin/
。第 1 步:查找节点当前在哪里
因此找到您的节点安装在哪里:
或者
第 2 步:创建符号链接
现在在
/usr/bin
中创建一个软链接第 3 步:验证符号链接
现在如果您再次运行 < code>whereis node 它应该打印两个路径。
如果您现在运行 capistrano,它应该可以正常工作而不会抛出 execjs 错误。
如何更新
如果您在项目的整个生命周期中更新已安装的
node
版本,您需要记住删除您创建的符号链接并使用安装的新node
版本重新安装它。我不会做的事情
node
版本管理器,我不会直接在服务器上安装节点。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 usebash
or inside.zshrc
if you usezsh
.What happens when you load the shell configuration file (automatically at startup time of the shell) is that the
$PATH
variable, is enriched with thenvm
path, such that alsonode
is findable. This is important, because all the paths put inside thePATH
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 hencenvm
and hencenode
are loaded. Therefore thenode
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:
or
Step 2: create symlink
Now create a soft link in
/usr/bin
Step 3: verify symlink
Now if you run again
whereis node
it should print both paths.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 newnode
version installed.Things I wouldn't do
node
version manager.execjs
because that library is working correctlytherubyracer
, 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, orexecjs
gem is not installed.2022 年 Mac 上的答案很简单:
brew install nodejs
然后重新运行
rails server
。The answer on a Mac in 2022 is simply:
brew install nodejs
Then rerun
rails server
.当我开始在 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.
在你的 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. :)
尝试使用 Ubuntu 18.04、Ruby 2.6.*、Rails 5 等在 RubyMine 中进行调试RubyMine 2019.1.1,我遇到了同样的问题。
为了解决该问题,我取消了
Gemfile
中mini_racer
行的注释,然后运行 bundle
:更改为:
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 myGemfile
and then ranbundle
:Change to:
我正在使用 Rails 7 和 bootstrap 5.2.3 Gem。在生产环境中,它在基于 Alpine Linux 的 Docker 容器中运行。就我而言,安装 Nodejs 和 npm 是不够的。我必须像这样安装纱线:
只有在那之后,错误消息才在生产中消失。
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:
Only after that, the error message disappeared on production.