vscode提示‘Vetur find `tsconfig.json`/`jsconfig.json`, but they aren‘t in the project root.’

2022-07-26,,,

实时更新。

问题1、vetur0.31.0,无法格式化.vue文件

2020-12-10 已经发布了 0.31.1 版本(Fix Vetur can’t format),安装新版即可(如果不会安装插件的固定版本,请看最后)。

问题2、Vetur find tsconfig.json/jsconfig.json, but they aren’t in the project root.

0.31.0版本新增了一个vetur.config.js的配置文件,在这个版本之后,会优先查找项目中是否配有tsconfig.json(ts项目)或者jsconfig.json(js项目),没找到再去找vetur.config.js,如果都没有,就会抛出这个提示

方案1、为对应项目(ts/js)添加json文件

以js项目为例,在根目录创建jsconfig.json,添加如下代码,详情参考文档

{
    "include": [
        "./src/*"
    ]
}

方案2、添加vetur.config.js

普通项目

// vetur.config.js
module.exports = {
    // vetur配置,会覆盖vscode中的设置。  default: `{}`
    settings: {
        "vetur.useWorkspaceDependencies": true,
        "vetur.experimental.templateInterpolationService": true
    },
    // 普通项目采用默认配置 default: `[{ root: './' }]`
}

大型项目,可参考文档

// vetur.config.js
module.exports = {
    // vetur配置
    settings: {
        "vetur.useWorkspaceDependencies": true,
        "vetur.experimental.templateInterpolationService": true
    },
    // support monorepos
    projects: [
        './packages/repo2', // shorthand for only root.
        {
            // **required**
            // Where is your project?
            // It is relative to `vetur.config.js`.
            root: './packages/repo1',
            // **optional** default: `'package.json'`
            // Where is `package.json` in the project?
            // We use it to determine the version of vue.
            // It is relative to root property.
            package: './package.json',
            // **optional**
            // Where is TypeScript config file in the project?
            // It is relative to root property.
            tsconfig: './tsconfig.json',
            // **optional** default: `'./.vscode/vetur/snippets'`
            // Where is vetur custom snippets folders?
            snippetFolder: './.vscode/vetur/snippets',
            // **optional** default: `[]`
            // Register globally Vue component glob.
            // If you set it, you can get completion by that components.
            // It is relative to root property.
            // Notice: It won't actually do it. You need to use `require.context` or `Vue.component`
            globalComponents: [
                './src/components/**/*.vue'
            ]
        }
    ]
}

方案3、配置vetur插件,忽略提示

在vscode的settings.json里面添加

vetur.ignoreProjectWarning: true

但是文档中有写可能会导致一些小问题,所以不妨添加个配置文件,也不麻烦。

If you don’t have any tsconfig.json, jsconfig.json in project, Vetur will use fallback settings. Some feature isn’t work. Like: path alias, decorator, import json.

PS:如果你需要,安装vscode插件历史版本的方法

找到你需要的版本

本文地址:https://blog.csdn.net/jsjcmq/article/details/110926639

《vscode提示‘Vetur find `tsconfig.json`/`jsconfig.json`, but they aren‘t in the project root.’.doc》

下载本文的Word格式文档,以方便收藏与打印。