2

So I have a couple of modules that I am importing in to my main.js and store.js file that are not being found when building in Netlify and I cannot understand why. When I run my build locally there is no issues.

So the 2 files are ability.js and storage.js

This is the alarm from the build in netlify

12:48:10 PM: These relative modules were not found:
12:48:10 PM: * ./utils/ability.js in ./src/main.js, ./src/store.js
12:48:10 PM: * ./utils/storage.js in ./src/store.js
12:48:10 PM:  ERROR  Build failed with errors.

Here is the ability.js file

import { Ability } from '@casl/ability'

export const ability = new Ability()

export const abilityPlugin = (store) => {
    ability.update(store.state.rules)

    const rules = store.subscribe((mutation) => {
        switch (mutation.type) {
            case 'createSession':
            ability.update(mutation.payload[0])
            break
            case 'destroySession':
            ability.update([{ actions: '', subject: '' }])
            break
        }
      })
      return rules
  }

here is the storage.js file

export default (options) => (store) => {
    if (localStorage.state) {
      const storedState = JSON.parse(localStorage.state)
      store.replaceState(Object.assign(store.state, storedState))
    }

    return store.subscribe((mutation, state) => {
      if (options.destroyOn && options.destroyOn.indexOf(mutation.type) !== -1) {
        return localStorage.removeItem('state')
      }

      const newState = options.storedKeys.reduce((map, key) => {
        map[key] = state[key]
        return map
      }, {})

      localStorage.state = JSON.stringify(newState)
    })
  }

and here are the 2 files where I import these modules

main.js

import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import { abilitiesPlugin } from '@casl/vue';
import { ability } from './utils/ability.js';

Vue.use(abilitiesPlugin, ability);

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')

store.js

import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import { abilityPlugin, ability as appAbility } from './utils/ability.js'
import storage from './utils/storage.js'

export const ability = appAbility
Vue.use(Vuex)
axios.defaults.baseURL = 'https://aewcpa.traxit.pro/api'
axios.defaults.headers.common['header1'] = {
  'X-Requested-With': 'XMLHttpRequest',
}



export default new Vuex.Store({
  plugins: [
    storage({
      storedKeys: ['rules', 'token'],
      destroyOn: ['destroySession']
    }),
    abilityPlugin
  ],
})

The directory structure with issues

enter image description here

The directory structure that currently works

enter image description here

TJ Weems
  • 1,086
  • 3
  • 21
  • 37

1 Answers1

1

Is Utils in the root of your project? Are you using the Vue Webpack Template?

If so the @ resolver is configured for you (ES6 import using at ('@') sign in path in a vue.js project using Webpack)

If so change:

from './utils/ability.js' to from '@/utils/storage.js'

and

from './utils/storage.js' to from '@/utils/storage.js'

Tim Wickstrom
  • 5,476
  • 3
  • 25
  • 33
  • @TimWistrom.com thank you for the reply! I actually tried that however the only solution I could find was moving `ability.js` and `storage.js` to the root of my `/src` directory. I will post the working tree in my question – TJ Weems Dec 21 '18 at 04:44
  • Are you using webpack? – Tim Wickstrom Dec 21 '18 at 17:08
  • no I am just using the standard configuration created with the vue cli plus vue router and vuex. I don't know how to include webpack configuration manually. I guess I should read into that and figure it out – TJ Weems Dec 21 '18 at 17:11
  • It is hard to tell from the screenshot do you have a config folder above your dist folder? If so what is in that folder? – Tim Wickstrom Dec 21 '18 at 17:14