路径别名的另一个问题。它们在任何地方都能完美工作,但不适用于电子文件。
在
vite.config.ts
我有resolve: {alias: {"@": "/src"}}
并且项目结构的(部分)是:
D:/Project/src
+ electron/modules/A.ts
+ shared/B.ts
+ components/C.vue
+ services/D.ts
+ types/index.d.ts
现在
C.vue
和 D.ts
有 import whatever from "@/shared/B"
可以毫无问题地工作。
相反,A.ts
会生成[vite]: Rollup failed to resolve import "@/shared/B" from "D:/Project/src/electron/modules/A.ts".
错误。
奇怪的是,
A.ts
中还有一个import type {aType} from "@/types"
,没有错误地解决了。
我尝试在别名定义中添加绝对路径,但没有任何变化。
我正在 Windows 11 上使用 vite 4.4.9。
感谢您的帮助! 马里奥
向上,我的 electro + vue 3 + typescript + vite 项目也有这个问题