vue.js [vite]:Rollup无法解析导入“image”从

11dmarpk  于 2023-05-07  发布在  Vue.js
关注(0)|答案(1)|浏览(845)

我的Vue 3 Vuetify SPA有问题。我可以很好地运行npm run dev,它加载资产,但是当我运行npm run build时,它无法构建,并出现错误

✓ built in 3.25s
[vite]: Rollup failed to resolve import "image" from "/Users/zachhandley/Documents/GitHub/OBrians/vuetify/src/views/Gallery.vue?vue&type=script&setup=true&lang.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "image" from "/Users/zachhandley/Documents/GitHub/OBrians/vuetify/src/views/Gallery.vue?vue&type=script&setup=true&lang.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at viteWarn (file:///Users/zachhandley/Documents/GitHub/OBrians/vuetify/node_modules/vite/dist/node/chunks/dep-a178814b.js:46546:23)
    at onRollupWarning (file:///Users/zachhandley/Documents/GitHub/OBrians/vuetify/node_modules/vite/dist/node/chunks/dep-a178814b.js:46570:9)
    at onwarn (file:///Users/zachhandley/Documents/GitHub/OBrians/vuetify/node_modules/vite/dist/node/chunks/dep-a178814b.js:46317:13)
    at Object.onwarn (file:///Users/zachhandley/Documents/GitHub/OBrians/vuetify/node_modules/rollup/dist/es/shared/node-entry.js:25287:13)
    at ModuleLoader.handleInvalidResolvedId (file:///Users/zachhandley/Documents/GitHub/OBrians/vuetify/node_modules/rollup/dist/es/shared/node-entry.js:23922:26)
    at file:///Users/zachhandley/Documents/GitHub/OBrians/vuetify/node_modules/rollup/dist/es/shared/node-entry.js:23882:26

我不知道是什么原因造成的,唯一的“形象”,我进口的画廊网页是

const imagePaths = import.meta.glob("@/assets/gallery/*.*", {
  as: "imagePath",
});

另外,如果我使用import.meta.glob("../../assets/gallery/*.*导入它,它不会加载任何图像。
什么原因会导致这种情况/我可以采取哪些步骤来修复它?

wvt8vs2t

wvt8vs2t1#

结果发现这个问题真的很愚蠢
在我的组件中,我使用了Vuetify的v-img

<v-img
        v-for="(src, index) of images"
        :key="src"
        class="mx-auto pageGallery__img--img"
        :src="src"
        lazy-src="image"
        cover
        @click="changeShowImage(index)"
      >
        <template v-slot:placeholder>
          <div class="pageGallery__placeholder">
            <v-progress-circular color="accent" indeterminate size="64" />
          </div>
        </template>
      </v-img>

lazy-src="image"线路导致错误。

相关问题