Virtual script not found, may missing <script lang="ts"> / "allowJs": true / jsconfig.json.volar
时间: 2023-07-08 13:12:27 浏览: 62
这个错误提示通常是在使用 Vue 3 + Volar 插件时出现的。它可能是由于以下原因之一导致的:
1. 你可能没有定义 `<script>` 标签或者没有指定 `lang="ts"`,导致 Volar 插件无法识别为 TypeScript 代码。
2. 你可能的项目中没有启用 TypeScript,可以在 tsconfig.json 中设置 `"allowJs": true` 来允许使用 JavaScript。
3. 如果你的代码是在 Vue 3 + TypeScript 项目中,你需要确保在项目根目录下存在一个名为 `jsconfig.json` 的文件,并且其中包含了你的项目的 TypeScript 配置。如果没有,可以手动创建该文件,并添加如下内容:
```json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"allowSyntheticDefaultImports": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"exclude": ["node_modules", "dist"]
}
```
如果你的项目中已经存在了 `tsconfig.json` 文件,则可以将 `jsconfig.json` 的配置与 `tsconfig.json` 同步。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)