Registry / web-framework / vue-ts-morph

vue-ts-morph

JSON →
library0.1.0jsnpmunverified

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.

npm install vue-ts-morph
INSTALL
IMPORT
SIG · VUE-TS-MORPH
V
vue-ts-morph
web-frameworkjavascriptv0.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createVueFileSystemHost
import { createVueFileSystemHost } from 'vue-ts-morph'
const createVueFileSystemHost = require('vue-ts-morph')
ESM-only; package ships TypeScript types. Default export not provided.
Project
import { Project } from 'ts-morph'
import { Project } from 'vue-ts-morph'
Project comes from ts-morph, not vue-ts-morph.
type VueFileSystemHost
import type { VueFileSystemHost } from 'vue-ts-morph'
import { VueFileSystemHost } from 'vue-ts-morph'
Type import for TypeScript users; VueFileSystemHost is not a runtime export.

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.

import { createVueFileSystemHost } from 'vue-ts-morph'; import { Project } from 'ts-morph'; const project = new Project({ fileSystem: createVueFileSystemHost(), }); project.addSourceFilesFromTsConfig('tsconfig.json'); const sourceFile = project.getSourceFileOrThrow('src/App.vue'); // Access TypeScript AST through the virtual .vue.ts file const vueTsSourceFile = sourceFile.getExtension() === '.vue' ? project.getSourceFileOrThrow('src/App.vue.ts') : sourceFile; if (vueTsSourceFile) { console.log('Classes:', vueTsSourceFile.getClasses().length); }
Debug
Known issues
breakingCannot read <template> section; only <script> (and <script setup>) content is available.
fix
Do not rely on template AST. Use a Vue compiler (e.g., @vue/compiler-sfc) separately if template analysis is needed.
affects: >=0.0.1
gotchaSimultaneous <script setup> and <script> blocks are not supported – only one script block per .vue file.
fix
Use only <script setup> or a single <script> block. Merge or split into separate files if both are needed.
affects: >=0.0.1
gotchaVirtual .vue.ts files are created on the fly; direct file system writes to .vue files may not be reflected without recreating the host.
fix
Always re-create the file system host (or project) after external modifications to .vue files.
affects: >=0.0.1
deprecatedPackage is experimental with no stable release or active maintenance guarantee.
fix
Consider using Volar's language service API if you need production-grade Vue TypeScript support.
affects: <1.0.0
Errors
Common errors & fixes
TypeError: fileSystem.readFileSync is not a function
Missing or incorrect file system host implementation.
fix
Use the provided createVueFileSystemHost() factory function instead of custom implementations.
Error: Cannot find module 'ts-morph'
Missing peer dependency ts-morph.
fix
Run: npm install ts-morph@^24.0.0
TypeError: sourceFile.getClasses is not a function
Accessing AST methods on the .vue source file instead of the virtual .vue.ts source file.
fix
Retrieve the virtual file: const vueFile = project.getSourceFileOrThrow('src/App.vue.ts');
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
ts-morphrequiredpeer dependency; vue-ts-morph extends ts-morph's Project with Vue file support. Must install separately.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
vue-ts-morph — npm install vue-ts-morph · libregistry