【问题标题】:Gem Load Error is: Node.js (V8) runtime is not available on this systemGem 加载错误是:Node.js (V8) 运行时在此系统上不可用
【发布时间】:2019-03-02 11:33:37
【问题描述】:

我正在使用 Capistrano 和 nginx 部署我的 rails 应用程序,当我尝试查看该应用程序时,它没有启动,我收到以下错误,尽管当我执行 which node 时,我得到了这个:

/home/ubuntu/.nvm/versions/node/v8.0.0/bin/node

虽然安装了node,但是报错是:

Gem Load Error is: Node.js (V8) runtime is not available on this system

如果我在rails c 运行ExecJS.eval "'red yellow blue'.split(' ')",我会得到预期的结果,所以 ExecJS 已经知道节点的安装位置..

编辑 PATH 已经包含节点的路径

$ echo $PATH
/home/ubuntu/.nvm/versions/node/v8.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

我正在使用没有 RVM 的 Ruby。

更多细节:

age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/my_app/current: The application encountered the following error: There was an error while trying to load the gem 'thredded'.
Gem Load Error is: Node.js (V8) runtime is not available on this system
Backtrace for gem load error is:
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:71:in `from_environment'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:57:in `autodetect'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/execjs-2.7.0/lib/execjs.rb:5:in `<module:ExecJS>'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/execjs-2.7.0/lib/execjs.rb:4:in `<top (required)>'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/autoprefixer-rails-9.4.9/lib/autoprefixer-rails/processor.rb:2:in `<top (required)>'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/autoprefixer-rails-9.4.9/lib/autoprefixer-rails.rb:36:in `require_relative'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/autoprefixer-rails-9.4.9/lib/autoprefixer-rails.rb:36:in `<top (required)>'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/thredded-0.15.5/lib/thredded.rb:28:in `<top (required)>'
/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:81:in `require'
/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:76:in `each'
/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:76:in `block in require'
/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:65:in `each'
/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:65:in `require'
/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/lib/bundler.rb:114:in `require'
/var/www/my_app/releases/20190302100032/config/application.rb:8:in `<top (required)>'
/var/www/my_app/releases/20190302100032/config/environment.rb:3:in `require'
/var/www/my_app/releases/20190302100032/config/environment.rb:3:in `<top (required)>'
config.ru:3:in `require'
config.ru:3:in `block in <main>'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/rack-1.6.8/lib/rack/builder.rb:55:in `instance_eval'
/var/www/my_app/shared/bundle/ruby/2.5.0/gems/rack-1.6.8/lib/rack/builder.rb:55:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:101:in `eval'
/usr/share/passenger/helper-scripts/rack-preloader.rb:101:in `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:189:in `block in <module:App>'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:380:in `run_block_and_record_step_progress'
/usr/share/passenger/helper-scripts/rack-preloader.rb:188:in `<module:App>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'

【问题讨论】:

    标签: node.js ruby-on-rails-4 nginx passenger execjs


    【解决方案1】:

    根据execjs 源代码,/home/ubuntu/.nvm/versions/node/v8.0.0/bin/node 很可能不在您的PATH 中。您可以从shellecho $PATHrails consoleENV['PATH'].split(File::PATH_SEPARATOR) 一样检查PATH。如果您的 node 路径不在您的路径中,则有两种方法。

    更新PATH 或在/usr/bin/usr/local/bin 目录中为您的node 创建符号链接,因为它们在PATH 中是默认的。

    【讨论】:

    • 另外,我可以使用/usr/bin/node/usr/local/bin/node 进入节点,我已经创建了符号链接,但它没有帮助..
    • 您的node 路径是否在ENV['PATH'] 中,当您在生产rails console 或您遇到此问题的任何地方点击时?
    • 是的,在rails c -e production 中,如果我在bash 中输入ENV['PATH'],我会得到与echo $PATH 相同的结果,即/var/www/dcaclab/shared/bundle/ruby/2.5.0/bin:/home/ubuntu/.nvm/versions/node/v8.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    • 您会运行此代码并在您的产品中分享输出吗? def node_exists? ["node", "nodejs"].find { |cmd| if File.executable? cmd cmd else path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p| full_path = File.join(p, cmd) File.executable?(full_path) &amp;&amp; File.file?(full_path) } path &amp;&amp; File.expand_path(cmd, path) end } end
    • 谢谢,我已经在生产控制台执行了,结果是:"node"
    猜你喜欢
    • 2015-11-06
    • 2016-03-03
    • 2016-07-12
    • 2017-06-21
    • 2019-10-05
    • 1970-01-01
    • 2021-10-27
    • 2017-04-28
    • 2020-03-06
    相关资源
    最近更新 更多