window.electron: Unresolved variable electron
joyexpr opened this issue · comments
Describe the bug
yarn create @quick-start/electron,选择vue typescript,在renderer中的vue组件中(如Versions.vue),window.electron 无法识别,在env.d.ts中添加以下声明也无效:
import { ElectronAPI } from '@electron-toolkit/preload'
declare global {
interface Window {
electron: ElectronAPI
api: unknown
}
}
Used Scaffolding
create-electron
Used Package Manager
yarn
Validations
- Follow the Code of Conduct.
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
有vue的IDE插件吗 TypeScript Vue Plugin (Volar),我在vscode下没有问题
webstorm没有volar插件,有安装官方的vue.js插件
试了下把tsconfig.web.json的内容拷到tsconfig.json就正常了
webstorm没有volar插件,有安装官方的vue.js插件
试了下把tsconfig.web.json的内容拷到tsconfig.json就正常了
这大致和IDE相关,webstorm不知道是用代码安装ts还是自带, references 要求 ts 3.0以上
显示是用的项目自带的依赖typescript 4.8.2,目前只用tsconfig.json和tsconfig.node.json暂未发现问题,我先继续留意
webstorm没有volar插件,有安装官方的vue.js插件
试了下把tsconfig.web.json的内容拷到tsconfig.json就正常了这大致和IDE相关,webstorm不知道是用代码安装ts还是自带, references 要求 ts 3.0以上
可能是跟IDE有关,我的IDE版本如下:macOS 10.15.7,WebStorm 2021.3,Vue.js插件版本:213.5744.224,typescript: 4.8.3
目前我尝试出来的尽量不修改模板的改动如下:
删除tsconfig.json中的 files:[] 这行,删除后 webstorm就可以resolve到window.electron了,不知道vscode删除这行会不会有影响。
---- 补充
删除files:[]后,执行typecheck(tsc --noEmit)会报错,把typecheck修改为另一个issue您回复的:
"typecheck": "tsc --noEmit -p tsconfig.node.json --composite false",
便正常了
另外建议把build中的tsc统一改成typecheck: "build": "npm run typecheck && electron-vite build",
还有lint script中,添加.vue 后缀
删除 files:[]
也是可以的,
typecheck这部分都要改,.vue 后缀也是