Vite rollup 不能仅解析电子文件的别名

问题描述 投票:0回答:1

路径别名的另一个问题。它们在任何地方都能完美工作,但不适用于电子文件。

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。

感谢您的帮助! 马里奥

electron vite alias rollup
1个回答
-1
投票

向上,我的 electro + vue 3 + typescript + vite 项目也有这个问题

© www.soinside.com 2019 - 2024. All rights reserved.