import.meta.glob和import.meta.globEager无法使用@绝对路径,只能使用相对路径
Open
- 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
Assessment
This issue has not been assessed yet.