前提・実現したいこと
Rails6でFullCalendarを導入しています。
開発環境でカレンダーの表示までできたのですが、
祝日をわかりやすく表示するためyarn add @fullcalendar/google-calendarコマンドでGoogleカレンダーのプラグインを追加しようとしたところ、
カレンダーが表示されなくなってしまいました。
発生している問題・エラーメッセージ
Console
Uncaught SyntaxError: Unexpected token '!'
該当のソースコード
app/javascript/packs/application.js以前
// This file is automatically compiled by Webpack, along with any other files // present in this directory. You're encouraged to place your actual application logic in // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. require("@rails/ujs").start() require("turbolinks").start() require("@rails/activestorage").start() require("channels") // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) // or the `imagePath` JavaScript helper below. // // const images = require.context('../images', true) // const imagePath = (name) => images(name, true) import { Calendar } from '@fullcalendar/core'; import dayGridPlugin from '@fullcalendar/daygrid'; import interactionPlugin from '@fullcalendar/interaction'; document.addEventListener('turbolinks:load', function() { var calendarEl = document.getElementById('calendar'); var calendar = new Calendar(calendarEl, { locale: 'ja', dayCellContent: function(e) { e.dayNumberText = e.dayNumberText.replace('日', ''); }, buttonText: { today: '今日', }, plugins: [ dayGridPlugin, interactionPlugin ] }); calendar.render(); });
app/javascript/packs/application.js作業後
// present in this directory. You're encouraged to place your actual application logic in // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. require("@rails/ujs").start() require("turbolinks").start() require("@rails/activestorage").start() require("channels") // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) // or the `imagePath` JavaScript helper below. // // const images = require.context('../images', true) // const imagePath = (name) => images(name, true) import { Calendar } from '@fullcalendar/core'; import dayGridPlugin from '@fullcalendar/daygrid'; import interactionPlugin from '@fullcalendar/interaction'; import googleCalendarApi from '@fullcalendar/google-calendar' document.addEventListener('turbolinks:load', function() { var calendarEl = document.getElementById('calendar'); var calendar = new Calendar(calendarEl, { locale: 'ja', dayCellContent: function(e) { e.dayNumberText = e.dayNumberText.replace('日', ''); }, buttonText: { today: '今日', }, plugins: [ dayGridPlugin, interactionPlugin, googleCalendarApi ], googleCalendarApiKey: 'xxxx', events: { googleCalendarId: 'ja.japanese#holiday@group.v.calendar.google.com', rendering: 'background', color:"#ffd0d0" } }); calendar.render(); });
package.json
{ "name": "habits", "private": true, "dependencies": { "@rails/actioncable": "^6.0.0-alpha", "@rails/activestorage": "^6.0.0-alpha", "@rails/ujs": "^6.0.0-alpha", "@rails/webpacker": "4.3.0", "turbolinks": "^5.2.0" }, "version": "0.1.0", "devDependencies": { "webpack-dev-server": "^4.2.1" } }
試したこと
試したyarnコマンド
rm -rf node_modules/
rm -rf yarn.lock
yarn install
yarn upgrade(実行不可)
package.jsonファイルが更新されていないことに気づきました。
補足情報(FW/ツールのバージョンなど)
Rails 6.0.4.1
node 17.0.1
yarn 1.22.17
初心者で初歩的な抜け漏れ等あると思いますがよろしくお願いします。
あなたの回答
tips
プレビュー