質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

1548閲覧

railsでExecJS::ProgramErrorのエラー画面が出てくる

kawauso0407

総合スコア0

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

1クリップ

投稿2021/05/14 16:05

前提・実現したいこと

ruby on rails において、task controller をつくり正常に 「XXX#index」の画面を表示したい。

発生している問題・エラーメッセージ

エラーが表示されて /index にアクセスした時に期待している画面が表示されない。

ExecJS::ProgramError in Tasks#index  Showing /app_name/app/views/layouts/application.html.slim where line #8 raised: TypeError: Cannot read property 'version' of undefined Rails.root: /app_name Application Trace | Framework Trace | Full Trace (execjs):19:14 (execjs):1:102 app/views/layouts/application.html.slim:8:in `_app_views_layouts_application_html_slim___3139678354113059132_70258517883120'

該当のソースコード

applicationhtmlslim

1doctype html 2html 3 head 4 title 5 | AppName 6 = csrf_meta_tags 7 = csp_meta_tag 8 = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' 9 = javascript_include_tag 'application', 'data-turbolinks-track': 'reload' 10 body 11 .app-title.navbar.navbar-expand-md.navbar-light.bg-light 12 .navbar-brand Taskleaf 13 .container 14 = yield 15

route

1Rails.application.routes.draw do 2 root to: 'tasks#index' 3 resources :tasks 4 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 5end

Gemfile

1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.5.3' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7gem 'rails', '~> 5.2.2' 8# Use mysql as the database for Active Record 9gem 'mysql2', '>= 0.4.4', '< 0.6.0' 10# Use Puma as the app server 11gem 'puma', '~> 3.11' 12# Use SCSS for stylesheets 13gem 'sass-rails', '~> 5.0' 14# Use Uglifier as compressor for JavaScript assets 15gem 'uglifier', '>= 1.3.0' 16# See https://github.com/rails/execjs#readme for more supported runtimes 17# gem 'mini_racer', platforms: :ruby 18 19# Use CoffeeScript for .coffee assets and views 20gem 'coffee-rails', '~> 4.2' 21# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 22gem 'turbolinks', '~> 5' 23# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 24gem 'jbuilder', '~> 2.5' 25# Use Redis adapter to run Action Cable in production 26# gem 'redis', '~> 4.0' 27# Use ActiveModel has_secure_password 28# gem 'bcrypt', '~> 3.1.7' 29 30# Use ActiveStorage variant 31# gem 'mini_magick', '~> 4.8' 32 33# Use Capistrano for deployment 34# gem 'capistrano-rails', group: :development 35 36# Reduces boot times through caching; required in config/boot.rb 37gem 'bootsnap', '>= 1.1.0', require: false 38 39group :development, :test do 40 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 41 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 42end 43 44group :development do 45 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 46 gem 'web-console', '>= 3.3.0' 47 gem 'listen', '>= 3.0.5', '< 3.2' 48 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 49 gem 'spring' 50 gem 'spring-watcher-listen', '~> 2.0.0' 51end 52 53group :test do 54 # Adds support for Capybara system testing and selenium driver 55 gem 'capybara', '>= 2.15' 56 gem 'selenium-webdriver' 57 # Easy installation and use of chromedriver to run system tests with Chrome 58 gem 'chromedriver-helper' 59end 60 61# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 62gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 63 64gem 'slim-rails' 65gem 'html2slim' 66gem 'bootstrap' 67gem 'execjs' 68gem 'therubyracer' 69 70gem 'coffee-script-source', '1.8.0'

試したこと

coffee-script-sourceを追記することで解決するとの記事を見つけ、試しましたが解決しませんでした。
またnodejsのパスが通ってない可能性を考えてnodejs -vを行いましたが、パスは正常に通っていました。

補足情報(FW/ツールのバージョンなど)

rails 5.2.2
ruby 2.5.3
mac Catalina 10.15.7

丁寧すぎるDocker-composeによるrails5 + MySQL on Dockerの環境構築(Docker for Mac)
https://qiita.com/azul915/items/5b7063cbc80192343fc0

上記の記事を参考にしてdocker-composeで環境を構築しました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

maisumakun

2021/05/14 21:35

javascript_include_tag 'application'としていますが、これで参照されるJavaScriptコードはどのようになっていますでしょうか?
kawauso0407

2021/05/15 02:15

ご返信ありがとうございます。 application.jsとtasks.coffeeは以下のようにコメントのみでした。 ```application // This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's // vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. JavaScript code in this file should be added after the last require_* statement. // // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require rails-ujs //= require activestorage //= require turbolinks //= require_tree . ``` ```taskscoffee # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://coffeescript.org/ ``` またcable.jsというのもありました。 以下のようになっております ```cablejs // Action Cable provides the framework to deal with WebSockets in Rails. // You can generate new channels where WebSocket features live using the `rails generate channel` command. // //= require action_cable //= require_self //= require_tree ./channels (function() { this.App || (this.App = {}); App.cable = ActionCable.createConsumer(); ```
guest

回答1

0

自己解決

理由はわかりませんがweb-packerをインストールしたら表示されました。
rails5ではwebpackerがなくても動くとおもっていたのですが違うようです。

$ docker-compose run web bundle exec rails webpacker:install
これでとりあえず表示はできるようになりました。

投稿2021/05/17 03:25

kawauso0407

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問