Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Grapedge opened this issue Feb 15, 2023 · 2 comments · Fixed by #3038
Closed

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

Grapedge opened this issue Feb 15, 2023 · 2 comments · Fixed by #3038
Labels
Playground Issues that affect the Playground

Comments

@Grapedge
Copy link

@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
    },
@Grapedge Grapedge added the Playground Issues that affect the Playground label Feb 15, 2023
@orta
Copy link
Contributor

orta commented Feb 15, 2023

Yeah, makes sense, I'd +1 a PR which changes that if(contents) to be one that checks for nulls & undefineds instead

@typescript-bot
Copy link
Collaborator

Hello! As per #2804, we are automatically closing all open issues. Please see #2804 for a description of what issues and PRs can be accepted going forward.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Playground Issues that affect the Playground
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants