打包时执行 "vue-tsc && vite build" 报错:
error TS2688: Cannot find type definition file for ''.
The file is in the program because:
Entry point for implicit type library ''
依赖版本如下:
"dependencies": {
"@vueuse/core": "^10.5.0",
"ant-design-vue": "4.x",
"pinia": "^2.1.6",
"sass": "^1.69.2",
"vue": "^3.3.4",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@types/node": "^20.10.0",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"@vitejs/plugin-vue": "^4.5.0",
"eslint": "^8.51.0",
"eslint-plugin-vue": "^9.17.0",
"postcss-syntax": "^0.36.2",
"typescript": "^5.4.2",
"unplugin-vue-components": "^0.25.2",
"vite": "^4.5.0",
"vue-tsc": "^1.8.5"
}
tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"typeRoots": [
"node_modules/@types", // 默认值
"types"
],
"paths": {
"@/*": [
"src/*"
],
"#/*": [
"types/*"
]
},
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "Node",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": [
"src/**/*.ts",
"types/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue"
],
"exclude": [
"node_modules",
"dist",
"**/*.js"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
因为不知道''(就是'')到底是什么,不知道从何入手,重新拉取了typescript也不行
目前通过注释/删除的方法大致确定:
是由于types/index.d.ts缺失导致的
推测是因为tsconfig.json里指定了typeRoots,会读目录下的index.d.ts