admin管理员组文章数量:1297029
I setup a mono repo with the following structure:
front-end
- apps
- desktop-app (An electron app created by electron-vite scaffolding)
- webapp (A mininal web app created by nx application scaffolding)
- packages
- shift-management (A react component library created by nx library scaffolding)
The alias path could be resolved correctly if I build the project using "pnpm run build" and run the output exe file.
// package.json snippet
"scripts": {
"dev": "vite",
"build": "tsc && vite build && electron-builder",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
However, if I want to use dev server by running "pnpm run dev", it will always throw out the following error during runtime. Why does vite with dev server doesn't recognize this alias path?
Error message electron project setup
I did configure both the tsconfig.json and vite.config.ts as specified in this tutorial:
// baseurl and paths created inside tsconfig.json
"baseUrl": ".",
"paths": {
"@": ["."],
"@hf-shift-management": ["packages/shift-management/src/index.ts"]
}
// alias created isnide vite.config.ts
resolve: {
alias: {
"@hf-shift-management": "../../packages/shift-management/src/index
}
}
I have tried the following:
- I replaced the import path @hf-shift-management with absolute path, the "vite" command succeed with dev server in runtime. This indicates that this is truly an alias issue
- I created a separate web-app project for debugging purpose. This webapp could successfully resolve the alias during runtime. So it seems to be related to some configuration issue, or maybe electron config issue.
I setup a mono repo with the following structure:
front-end
- apps
- desktop-app (An electron app created by electron-vite scaffolding)
- webapp (A mininal web app created by nx application scaffolding)
- packages
- shift-management (A react component library created by nx library scaffolding)
The alias path could be resolved correctly if I build the project using "pnpm run build" and run the output exe file.
// package.json snippet
"scripts": {
"dev": "vite",
"build": "tsc && vite build && electron-builder",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
However, if I want to use dev server by running "pnpm run dev", it will always throw out the following error during runtime. Why does vite with dev server doesn't recognize this alias path?
Error message electron project setup
I did configure both the tsconfig.json and vite.config.ts as specified in this tutorial: https://dev.to/tilly/aliasing-in-vite-w-typescript-1lfo
// baseurl and paths created inside tsconfig.json
"baseUrl": ".",
"paths": {
"@": ["."],
"@hf-shift-management": ["packages/shift-management/src/index.ts"]
}
// alias created isnide vite.config.ts
resolve: {
alias: {
"@hf-shift-management": "../../packages/shift-management/src/index
}
}
I have tried the following:
- I replaced the import path @hf-shift-management with absolute path, the "vite" command succeed with dev server in runtime. This indicates that this is truly an alias issue
- I created a separate web-app project for debugging purpose. This webapp could successfully resolve the alias during runtime. So it seems to be related to some configuration issue, or maybe electron config issue.
1 Answer
Reset to default 0As mentioned in the following post, path alias is an old way for replacing relative imports in monorepos. Path alias are a purely compile-time construct. To run the application, you will need a runtime plugin
With workspace concepts coming in pnpm/yarn/etc, it is recommended to use workspaces + project references as mentioned in the following ost:
https://nx.dev/blog/managing-ts-packages-in-monorepos
本文标签: ElectronVite fails to resolve alias path during quotvitequot task onlyStack Overflow
版权声明:本文标题:Electron-Vite fails to resolve alias path during "vite" task only - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741640951a2389913.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论