Skip to content

Conversation

@fengzilong
Copy link

@fengzilong fengzilong commented Mar 22, 2025

After applying env.updateFile to reset a file's content to empty, then use any env.languageService.* method, it would throw an error message stating "Could not find source file: 'index.ts'"

import {
  createDefaultMapFromCDN,
  createSystem,
  createVirtualTypeScriptEnvironment,
} from '@typescript/vfs';
import ts from 'typescript';

const fsMap = await createDefaultMapFromCDN(
  { target: ts.ScriptTarget.ES2018 },
  '5.7.2',
  false,
  ts
);

const system = createSystem(fsMap);

const compilerOpts = {};
const env = createVirtualTypeScriptEnvironment(system, [], ts, compilerOpts);

env.createFile('/index.ts', 'console.logx()');

env.updateFile('/index.ts', '');

// throws error: Could not find source file: 'index.ts'.
env.languageService.getSemanticDiagnostics('index.ts');

Here is the repro: https://stackblitz.com/edit/vitejs-vite-obbb75xc?file=src%2Findex.ts

This PR fixes this

@fengzilong
Copy link
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant