dcloudio / dcloudio/uni-app

import.meta.glob和import.meta.globEager无法使用@绝对路径,只能使用相对路径

Open
#4,135 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
41.6k
Forks
3.7k
Avg merge
7h 6m
Merged PRs (30d)
6

Description

在无意间发现将绝对路径替换为相对路径则不会出问题,但在普通vue项目中不存在这个问题。
以下是原提问:
---
在执行dev:h5时候报错:
```
[plugin:vite:import-glob]Cannot find module 'D:/xxx/*.svg' from 'D:/xxx/src/components/svg-
raw/svg-raw.vue'
```
控制台报错
```
index.vue:1
GET http://localhost:5173/src/components/svg-raw/svg-raw.vue?t=1675687847648 net::ERR_ABORTED 500 (Internal Server Error)
```
```
vue.runtime.esm.js:1403
TypeError: Failed to fetch dynamically imported module: http://localhost:5173/src/pages/index/index.vue?t=1675687847648
```

代码如下:
```ts
const modules = import.meta.globEager('@/assets/svg/*.svg')
// 或
// const modules = import.meta.glob('@/stores/*.ts', { eager: true })
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.