0
votes

I'm trying to import a json file in my vue component but its giving this error

ERROR in ./~/buble-loader?{"objectAssign":"Object.assign"}!./~/vue-loader/lib/selector.js?type=script&index=0!./resources/assets/src/App.vue Module not found: Error: Can't resolve 'assets/incomingData.json' in '/var/www/html/mac/resources/assets/src'

script:

import jsonData from 'assets/incomingData.json'

export default {
  name: 'app',
  data () {
    return {
      entryData: jsonData,
      outputData: ''
    }
  },
  created () {
    this.$store.commit('setEntryData', this.entryData['bundle'])
    this.$store.commit('setTargetRate', this.entryData.targetNetRate)
  },
  beforeMount () {
    this.$store.dispatch('calculate').then(res => {
      this.outputData = this.$store.getters.getCalculatedData
    })
  }
}

folder structure:

enter image description here

package.json

enter image description here

any suggestions how do I fix this issue ?

1
Move assets into pubilc folder and try like import jsonData from '/assets/incomingData.json'Niklesh Raut
Is App.vue is inside store folder ?Niklesh Raut
@user2486 : yes App.vue is in store folder06011991
@06011991 are you sure about that? Doesn't look like in the image.yuriy636
@06011991 : so just check by using import jsonData from 'assets/incomingData.json' ? without .. double dotNiklesh Raut

1 Answers

0
votes

The assets folder is at the same level as your App.vue file (which you are importing the json file from).

In order to import something from the same level, you start your import path with ./

import jsonData from './assets/incomingData.json'

If you don't use ./ webpack will try to find a package in node_modules named "assets", instead of a folder.