前提
Ruby on Rails とVue.jsでカレンダーを作っています。
2つのコンポーネント間でデータを共有を実装中に以下のエラーメッセージが発生しました。
実現したいこと
- Vuexを使ってコンポーネント間でデータを共有する
- CalenderのデータをCalendarDetailsで共有
発生している問題・エラーメッセージ
Module parse failed: Unexpected token (3:0) File was processed with these loaders: * ./node_modules/vue-loader/dist/index.js You may need an additional loader to handle the result of these loaders. | | import {} > import { mapGetters, mapActions } from 'vuex'; | import CalendarDetails from './CalendarDetails.vue'; | ERROR /Users/xxxxxxxxxxx/Desktop/Calendar/frontend/src/components/Calendar.vue 16:0 error Parsing error: 'from' expected``` ### 該当のソースコード
Calendar.vue
1<template> 2 --- 3</template> 4<script> 5import {} 6import { mapGetters, mapActions } from 'vuex'; 7import CalendarDetails from './CalendarDetails.vue'; 8 9export default { mapGetters, mapActions } from 'vuex'; 10 name: 'Calendar', 11 components: { 12 CalendarDetails, 13 }, 14 computed: { 15 ...mapGetters('events', ['events']), 16 }, 17 methods: { 18 ...mapActions('events', ['fetchEvents']), 19 }, 20}; 21</script>
events.js
1import axios from 'axios'; 2 3const apiUrl = 'http://localhost:3000'; 4 5const state = { 6 event: [], 7}; 8 9const getters = { 10 events: (state) => state.events, 11}; 12 13const mutations = { 14 setEvents: (state, events) => (state.events = events), 15}; 16 17const actions = { 18 async fetchEvents({ commit }) { 19 const response = await axios.get(`${apiUrl}/events`); 20 commit('setEvents', response.data); 21 }, 22}; 23 24export default { 25 namespace: true, 26 state, 27 getters, 28 mutations, 29 actions, 30}; 31
index.js
1import { createStore } from 'vuex'; 2import events from './modules/events'; 3 4export default createStore({ 5 state: {}, 6 getters: {}, 7 mutations: {}, 8 actions: {}, 9 modules: { 10 events, 11 }, 12});
module.exports = { plugins: ['@typescript-eslint'], parser: 'vue-eslint-parser', root: true, env: { node: true, }, extends: [ 'plugin:vue/base', 'plugin:vue/vue3-essential', 'eslint:recommended', 'plugin:prettier/recommended', 'plugin:vue/recommended', 'plugin:@typescript-eslint/eslint-recommended', ], parserOptions: { ecmaVersion: 7, sourceType: 'module', parser: '@typescript-eslint/parser', ecmaFeatures: { jsx: true, modules: true }, }, rules: { 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'vue/multi-word-component-names': 0, 'no-undef': 'off', 'no-unused-vars': 'off', strict: 'off', 'vue/no-unused-components': 'off', }, };
試したこと
tslintを使わずにtypescript系のlintエラー対応する方法の記事を参考にし依存パッケージをインストールしました。
json
1{ 2 "root": true, 3 "extends": ["plugin:vue/recommended"], 4 "parserOptions": { 5 "parser": "@typescript-eslint/parser" 6 }, 7 "plugins": ["@typescript-eslint"], 8 "rules": { 9 "no-undef": "off", 10 "no-unused-vars": "off", 11 "strict": "off" 12 } 13}
sh
1npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-vue
エラーは解決せず、ほのかの記事も同じような記述方だったので解決方法がわかりません。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。