Module parse failed: Unexpected token (1:0) vue.js vuex store

Teoman Kirac

Can't figure out this error with vuex store and vue.js:

Is this a webpack-cli thing? or am i not doing something right? Thanks for the help!

Module parse failed: /Users/me/sites/vue/src/components/SectionView.Vue Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <template>
|   <ul class="listing">
|      <li v-for="item in $store.state.items">

 @ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/PanelBody.vue 3:0-56
 @ ./src/components/PanelBody.vue
 @ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Panel.vue
 @ ./src/components/Panel.vue
 @ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Accordion.vue
 @ ./src/components/Accordion.vue
 @ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Sidebar.vue
 @ ./src/components/Sidebar.vue
 @ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Body.vue
 @ ./src/components/Body.vue
 @ ./src/router/index.js
 @ ./src/main.js
 @ multi ./build/dev-client ./src/main.js

My SectionView.vue file:

<template>
  <ul class="listing">
     <li v-for="item in $store.state.items">
       <router-link :to="{ name: 'item', params: { id: item.id }}">
         <img :src="item.image" />
         <br>{{ item.name }}
       </router-link>
     </li>
   </ul>
</template>

<script>
import Item from '../components/Item',
export default {
  name: 'SectionView',
  components: {
    'item': Item
  },
  created () {
    this.$store.dispatch('fetch')
  }
},
}
</script>

My Item.vue:

<template>
  <div id="section-view">
    <div class="item-view">
      <router-link class="back-listing" :to="{name: 'section'}">U+0003C</router-link>
      <div class="item">
        <h1>{{ item.name }}</h1>
        </div>
    </div>
</template>

<script>
export default {
  name: 'item',
  computed: {
    item: function () {
      return this.$store.state.items.find(item => item.id === this.$route.params.id)
    }
  },
  created () {
    this.$store.dispatch('open', this.$route.params.id)
  }
}
</script>

My store which is in a src/store/index.js:

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const db = [
  { id: 'a', name: 'Item #1', image: 'http://lorempicsum.com/simpsons/350/200/1' },
  { id: 'b', name: 'Item #2', image: 'http://lorempicsum.com/simpsons/350/200/2' },
  { id: 'c', name: 'Item #3', image: 'http://lorempicsum.com/simpsons/350/200/3' }
]

const store = new Vuex.Store({

  state: {
    items: [],
    opened: {}
  },

  actions: {
    fetch: function ({commit, state}, payload) {
      commit('SET_LIST', db) // Just clone the array
    },
    open: function ({commit, state}, payload) {
      // look for item in local state
      var localItem = state.items.find(item => payload === item.id)
      if (!localItem) {
        new Promise(function (resolve, reject) {
          return db.find(item => payload === item.id)
        })
        .then(result => {
          commit('ADD_ITEM', result)
        })
      }
    }
  },

  mutations: {
    SET_LIST: function (state, payload) {
      Vue.set(state, 'items', payload)
    },
    ADD_ITEM: function (state, playload) {
      state.items.push()
    }
  }

})

console.log('State', store)
export default store

And my main.js calling the store:

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import store from './store'
import App from './App'
import router from './router'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  template: '<App/>',
  components: { App }
})
Doctor

Like @MateenRay said the ".Vue" instead ".vue" really could be the issue.

This is all about your operating system.

On windows "FILE.txt" and "file.txt" are the same. So when calling you vue file upper or down case it doesn't matter.

But for linux "FILE.txt" and "file.txt" are two separate files ! So calling your ".Vue" file is not the same as calling the ".vue" one.

Its important to remember this because on my project we were on windows and didn't pay attention to this. Next we changed all our file names from "file" to "File". Next we had to deliver it on a linux machine and nothing was working because some files were not found... Some of us were still importing files like the following :

import file from ... instead of import File from ...

It was working on windows but not on linux.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

React JS: ERROR in index.css 1:0 (Module parse failed: Unexpected token (1:0))

From Dev

Vue Module parse failed: Unexpected token

From Dev

Next JS: Module parse failed: Unexpected character '�' (1:0)

From Dev

Module parse failed: Unexpected character '@' (1:0)

From Dev

Module parse failed: Unexpected token

From Dev

vue js serve problem - Module parse failed: Unexpected token (763:13)

From Dev

webpack 4 - Module parse failed: Unexpected character '�' (1:0) on simple JS file

From Dev

How to fix Module parse failed: Unexpected token?

From Dev

webpack tsx Module parse failed: Unexpected token

From Dev

Module parse failed: Unexpected token ionic 3

From Dev

Module parse failed: Unexpected token (7855:112)

From Dev

Webpack failed to parse TypeScript module: Unexpected token

From Dev

Module parse failed: Unexpected token (11:19)

From Dev

Cant import video file Module parse failed: Unexpected character ' ' (1:0) React.js Next.js

From Dev

Webpack 4 basic React js hello world fails with "Module parse failed: Unexpected token"

From Dev

React and Webpack Module parse failed: /testimonials.js Unexpected token (6:4)

From Dev

Module parse failed: Unexpected token. react-native/index.js "typeof" operator

From Dev

Module parse failed: Unexpected token when using webpack 5

From Dev

Webpack error after upgrading Node: "Module parse failed: Unexpected token"

From Dev

Module parse failed: Unexpected token using webpack-dev-server

From Dev

Module Parse Failed: Unexpected token in Webpack Typescript Loader

From Dev

Module parse failed: Unexpected token on React Component Render

From Dev

Module parse failed: Unexpected token (9:37) with babel-loader

From Dev

Module parse failed: Unexpected token (14:6) while heroku deployment

From Dev

CSS Module parse failed: Unexpected token Angular 14?

From Dev

Module parse failed: Unexpected character '' (1:0) when adding ttf to my stylesheet

From Dev

Module parse failed: Unexpected character '@' (1:0) with Storybook 6.1.11, Webpack 5.11.0, React 17.0.1

From Dev

Module parse failed: Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type

From Dev

Module parse failed: Unexpected character '@' (1:0) - You may need an appropriate loader to handle this file type

Related Related

  1. 1

    React JS: ERROR in index.css 1:0 (Module parse failed: Unexpected token (1:0))

  2. 2

    Vue Module parse failed: Unexpected token

  3. 3

    Next JS: Module parse failed: Unexpected character '�' (1:0)

  4. 4

    Module parse failed: Unexpected character '@' (1:0)

  5. 5

    Module parse failed: Unexpected token

  6. 6

    vue js serve problem - Module parse failed: Unexpected token (763:13)

  7. 7

    webpack 4 - Module parse failed: Unexpected character '�' (1:0) on simple JS file

  8. 8

    How to fix Module parse failed: Unexpected token?

  9. 9

    webpack tsx Module parse failed: Unexpected token

  10. 10

    Module parse failed: Unexpected token ionic 3

  11. 11

    Module parse failed: Unexpected token (7855:112)

  12. 12

    Webpack failed to parse TypeScript module: Unexpected token

  13. 13

    Module parse failed: Unexpected token (11:19)

  14. 14

    Cant import video file Module parse failed: Unexpected character ' ' (1:0) React.js Next.js

  15. 15

    Webpack 4 basic React js hello world fails with "Module parse failed: Unexpected token"

  16. 16

    React and Webpack Module parse failed: /testimonials.js Unexpected token (6:4)

  17. 17

    Module parse failed: Unexpected token. react-native/index.js "typeof" operator

  18. 18

    Module parse failed: Unexpected token when using webpack 5

  19. 19

    Webpack error after upgrading Node: "Module parse failed: Unexpected token"

  20. 20

    Module parse failed: Unexpected token using webpack-dev-server

  21. 21

    Module Parse Failed: Unexpected token in Webpack Typescript Loader

  22. 22

    Module parse failed: Unexpected token on React Component Render

  23. 23

    Module parse failed: Unexpected token (9:37) with babel-loader

  24. 24

    Module parse failed: Unexpected token (14:6) while heroku deployment

  25. 25

    CSS Module parse failed: Unexpected token Angular 14?

  26. 26

    Module parse failed: Unexpected character '' (1:0) when adding ttf to my stylesheet

  27. 27

    Module parse failed: Unexpected character '@' (1:0) with Storybook 6.1.11, Webpack 5.11.0, React 17.0.1

  28. 28

    Module parse failed: Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type

  29. 29

    Module parse failed: Unexpected character '@' (1:0) - You may need an appropriate loader to handle this file type

HotTag

Archive