vite(vue)+typescript error TS2304: Cannot find name 'title'

Viewed 408

I am using vite(vue)+typescript for my project.

but when I run yarn build (vue-tsc --noEmit && vite build)

showing a bunch of this kind of error.

error TS2304: Cannot find name 'title'. enter image description here

but I'm pretty sure I did defined those variable.

enter image description here

I guess this is because the setup in <script setup lang="ts">?

here is my tsconfig.

{
  "compilerOptions": {
    "target": "esnext",
    "useDefineForClassFields": true,
    "module": "esnext",
    "moduleResolution": "node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "lib": [
      "esnext",
      "dom"
    ],
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "isolatedModules": true,
    "skipLibCheck": true
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.d.ts",
    "src/**/*.tsx",
    "src/**/*.vue"
  ],
  "references": [
    {
      "path": "./tsconfig.node.json"
    }
  ]
}
2 Answers

simply upgrade vue-tsc version with npm i vue-tsc -D

I got the same issue with typescript version 4.8.2 and old vue-tsc version 0.2.3, fixed it with typescript 4.8.2 and vue-tsc 0.40.5 (the latest version)

Related