所以我有几个模块要导入到我的 main.js
和 store.js
文件中,在 Netlify 中构建时找不到这些模块,我不明白为什么。当我在本地运行我的构建时,没有任何问题。
所以这 2 个文件是 ability.js
和 storage.js
这是 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.
这里是ability.js文件
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
}
这里是 storage.js 文件
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)
})
}
这是我导入这些模块的 2 个文件
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
],
})
有问题的目录结构
当前工作的目录结构
最佳答案
Utils 是否在您项目的根目录中?您在使用 Vue Webpack 模板吗?
如果是这样,@ 解析器已为您配置 ( ES6 import using at ('@') sign in path in a vue.js project using Webpack )
如果这样改变:
从 './utils/ability.js'
到 从 '@/utils/storage.js'
和
从 './utils/storage.js'
到 从 '@/utils/storage.js'
关于javascript - Netlify Vue 构建找不到导出模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53874529/