Skip to content

Module(vfs): throws an error when the file content is empty string #2713

Description

@Grapedge

@typescript/vfs

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

;(async () => {
  const compilerOptions = {
    target: ScriptTarget.ES2015,
  }
  const fsMap = await createDefaultMapFromCDN(compilerOptions, ts.version, true, ts)
  fsMap.set('index.ts', '') // error
  const system = createSystem(fsMap)
  const env = createVirtualTypeScriptEnvironment(system, ['index.ts'], ts, compilerOptions)
})()

Error:

Uncaught (in promise) Error: error TS6053: File 'index.ts' not found.
  The file is in the program because:
    Root file specified for compilation

    at Module.createVirtualTypeScriptEnvironment (index.ts:58:11)

It may be because of this:

// "@typescript/vfs" line 553:
    getScriptSnapshot: fileName => {
      const contents = sys.readFile(fileName)
      if (contents) { // <=
        return ts.ScriptSnapshot.fromString(contents)
      }
      return
    },

Metadata

Metadata

Assignees

No one assigned

    Labels

    PlaygroundIssues that affect the Playground

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions