Thanks to visit codestin.com
Credit goes to github.com

Skip to content

vue-component-meta: checker not working with tsconfig that uses references #3896

@larsrickert

Description

@larsrickert

When using vue-component-meta with a tsconfig.json that uses references (like the one that is provided by the official Vue starter), the checker will throw an error "Could not find main source file" and does not provide any meta.

Versions

node: 20.10.0
typescript: 5.3.3
vue-component-meta: 1.8.27
vue: 3.4.19
@vue/tsconfig: 0.5.1
@tsconfig/node20: 20.1.2

Reproduction

Vue component:

// src/TestComponent.vue
<script setup lang="ts">
defineProps<{
  /** Test property */
  test: string;
}>();
</script>

<template>Example component</template>

vue-component-meta Code:

// src/test.ts
import path from "node:path";
import { fileURLToPath } from "node:url";
import type { MetaCheckerOptions } from "vue-component-meta";
import { createComponentMetaChecker } from "vue-component-meta";

const __dirname = fileURLToPath(new URL(".", import.meta.url));

const checkerOptions: MetaCheckerOptions = {
  forceUseTs: true,
  noDeclarations: true,
  printer: { newLine: 1 },
};

const checker = createComponentMetaChecker(
  // if you change the file to "tsconfig.app.json" which does not use references, the checker works
  path.join(__dirname, "..", "tsconfig.json"),
  checkerOptions,
);

const componentPath = path.join(__dirname, "./TestComponent.vue");
const meta = checker.getComponentMeta(componentPath);
console.log(JSON.stringify(meta, null, 2));

tsconfig.json file

{
  "files": [],
  "references": [
    { "path": "./tsconfig.node.json" },
    { "path": "./tsconfig.app.json" }
  ]
}

tsconfig.app.json file:

{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "include": ["env.d.ts", "src/**/*"],
  "compilerOptions": {
    "composite": true,
    "rootDir": "./src",
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

tsconfig.node.json file:

{
  "extends": "@tsconfig/node20/tsconfig.json",
  "include": ["vite.config.ts"],
  "compilerOptions": {
    "composite": true,
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "types": ["node"]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions