简体   繁体   English

Netlify Vue 构建无法找到导出模块

[英]Netlify Vue Build Failing To Find Export Modules

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.所以我有几个模块要导入到我的main.jsstore.js文件中,但在 Netlify 中构建时找不到这些模块,我不明白为什么。 When I run my build locally there is no issues.当我在本地运行构建时,没有问题。

So the 2 files are ability.js and storage.js所以这两个文件是ability.jsstorage.js

This is the alarm from the build in netlify这是 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这是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
  }

here is the storage.js file这是 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)
    })
  }

and here are the 2 files where I import these modules这是我导入这些模块的 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商店.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有问题的目录结构

在此处输入图片说明

The directory structure that currently works当前有效的目录结构

在此处输入图片说明

Is Utils in the root of your project? Utils 是否在您项目的根目录中? Are you using the Vue Webpack Template?你在使用 Vue Webpack 模板吗?

If so the @ resolver is configured for you ( ES6 import using at ('@') sign in path in a vue.js project using Webpack )如果是这样,则为您配置了 @ 解析器( 使用 Webpack 的 vue.js 项目中使用 at ('@') 登录路径的 ES6 导入

If so change:如果是这样改变:

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

and

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vue JS构建失败 - Vue js build is failing Netlify 在导入/导出模块时抛出错误,为什么? - Netlify throwing error when import/export modules, why? Vue + Typescript + Webpack:模块构建失败 - 找不到vue.esm.js - Vue + Typescript + Webpack: Module build failing - Can't find vue.esm.js Vue CLI 3 - 构建不会因 lint 错误而失败 - Vue CLI 3 - Build not failing on lint errors Vue Custom Element无法在Dist中构建独立的JS文件 - Vue Custom Element failing to build standalone JS files in Dist Vue.js 项目 - CSS 模块的模块构建失败 - Vue.js project - Module build failed with CSS Modules AWS Amplify 代码构建错误为我添加隔离模块然后构建失败 - AWS Amplify Code Build Error of Adding Isolated Modules For Me Then Failing The Build 带有 Webpack 的 Vanilla Javascript 项目无法在 netlify 上部署 - Vanilla Javascript project with Webpack failing to deploy on netlify Gatsby/Wordpress 站点的 Netlify 部署失败 - Netlify deployment of Gatsby/Wordpress site failing 未捕获的语法错误:请求的模块“/@modules/vue.js”未提供名为“默认”的导出 - Uncaught SyntaxError: The requested module '/@modules/vue.js' does not provide an export named 'default'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM