{"id":18920,"library":"vue-ts-morph","title":"Vue TS Morph","description":"A thin library that enables ts-morph (TypeScript compiler API wrapper) to understand Vue single-file components (.vue files). Current version 0.1.0 wraps ts-morph ^24.0.0. Unlike Volar or Vetur, which implement custom LanguageServiceHosts, vue-ts-morph works at the FileSystemHost level—creating virtual .vue.ts files that shadow real .vue files. This makes it the only option for using ts-morph's AST manipulation API (e.g., refactoring, code generation) directly on Vue SFCs without a full language server. Released as experimental (no stable release cadence). Not recommended for production; major limitations: no <template> support, no simultaneous <script setup> + <script> blocks.","status":"active","version":"0.1.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install vue-ts-morph","lang":"bash","label":"npm"},{"cmd":"yarn add vue-ts-morph","lang":"bash","label":"yarn"},{"cmd":"pnpm add vue-ts-morph","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; vue-ts-morph extends ts-morph's Project with Vue file support. Must install separately.","package":"ts-morph","optional":false}],"imports":[{"note":"ESM-only; package ships TypeScript types. Default export not provided.","wrong":"const createVueFileSystemHost = require('vue-ts-morph')","symbol":"createVueFileSystemHost","correct":"import { createVueFileSystemHost } from 'vue-ts-morph'"},{"note":"Project comes from ts-morph, not vue-ts-morph.","wrong":"import { Project } from 'vue-ts-morph'","symbol":"Project","correct":"import { Project } from 'ts-morph'"},{"note":"Type import for TypeScript users; VueFileSystemHost is not a runtime export.","wrong":"import { VueFileSystemHost } from 'vue-ts-morph'","symbol":"type VueFileSystemHost","correct":"import type { VueFileSystemHost } from 'vue-ts-morph'"}],"quickstart":{"code":"import { createVueFileSystemHost } from 'vue-ts-morph';\nimport { Project } from 'ts-morph';\n\nconst project = new Project({\n  fileSystem: createVueFileSystemHost(),\n});\nproject.addSourceFilesFromTsConfig('tsconfig.json');\n\nconst sourceFile = project.getSourceFileOrThrow('src/App.vue');\n// Access TypeScript AST through the virtual .vue.ts file\nconst vueTsSourceFile = sourceFile.getExtension() === '.vue' ? project.getSourceFileOrThrow('src/App.vue.ts') : sourceFile;\nif (vueTsSourceFile) {\n  console.log('Classes:', vueTsSourceFile.getClasses().length);\n}","lang":"typescript","description":"Shows how to create a ts-morph Project that can read .vue files, add source files from tsconfig, then access the virtual .vue.ts file to query TypeScript AST."},"warnings":[{"fix":"Do not rely on template AST. Use a Vue compiler (e.g., @vue/compiler-sfc) separately if template analysis is needed.","message":"Cannot read <template> section; only <script> (and <script setup>) content is available.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Use only <script setup> or a single <script> block. Merge or split into separate files if both are needed.","message":"Simultaneous <script setup> and <script> blocks are not supported – only one script block per .vue file.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Always re-create the file system host (or project) after external modifications to .vue files.","message":"Virtual .vue.ts files are created on the fly; direct file system writes to .vue files may not be reflected without recreating the host.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Consider using Volar's language service API if you need production-grade Vue TypeScript support.","message":"Package is experimental with no stable release or active maintenance guarantee.","severity":"deprecated","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use the provided createVueFileSystemHost() factory function instead of custom implementations.","cause":"Missing or incorrect file system host implementation.","error":"TypeError: fileSystem.readFileSync is not a function"},{"fix":"Run: npm install ts-morph@^24.0.0","cause":"Missing peer dependency ts-morph.","error":"Error: Cannot find module 'ts-morph'"},{"fix":"Retrieve the virtual file: const vueFile = project.getSourceFileOrThrow('src/App.vue.ts');","cause":"Accessing AST methods on the .vue source file instead of the virtual .vue.ts source file.","error":"TypeError: sourceFile.getClasses is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}