question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

disparity between new Project and createIncrementalProgram

See original GitHub issue

Describe the bug

Version: 7.1.0

To Reproduce

I don’t have a fully isolated repro yet. But here is the diff I’m working with:

before:

   const tsconfigOptions = {
     ...compilerCacheOptions,
     ...layout.tsConfig.content.options,
     outDir: layout.build.tsOutputDir,
   }

   const builder = ts.createIncrementalProgram({
     rootNames: layout.nexusModules.concat(layout.app.exists ? [layout.app.path] : []),
     options: tsconfigOptions
  })

  const errors = project.getPreEmitDiagnostics() // is fine

after:

   const tsconfigOptions = {
     ...compilerCacheOptions,
     ...layout.tsConfig.content.options,
     outDir: layout.build.tsOutputDir,
   }

   const project = new tsm.Project({
     compilerOptions: tsconfigOptions,
   })

   project.addSourceFilesAtPaths(layout.nexusModules.concat(layout.app.exists ? [layout.app.path] : []))

  const errors = project.getPreEmitDiagnostics() // has a diagnostic error

unexpected diagnostic error happened with after case:

[
  Diagnostic {
    _context: ProjectContext {
      logger: [ConsoleLogger],
      manipulationSettings: [ManipulationSettingsContainer],
      _project: [Project],
      fileSystemWrapper: [TransactionalFileSystem],
      _compilerOptions: [CompilerOptionsContainer],
      compilerFactory: [CompilerFactory],
      inProjectCoordinator: [InProjectCoordinator],
      structurePrinterFactory: [StructurePrinterFactory],
      lazyReferenceCoordinator: [LazyReferenceCoordinator],
      directoryCoordinator: [DirectoryCoordinator],
      _languageService: [LanguageService]
    },
    _compilerObject: {
      file: undefined,
      start: undefined,
      length: undefined,
      messageText: "Cannot find type definition file for 'fs'.",
      category: 1,
      code: 2688,
      reportsUnnecessary: undefined
    }
  }
]

Expected behavior

Can seamlessly transition from ts.createIncrementalProgram to new tsm.Project.

I suspect this isn’t a bug but incorrectly ts-morph usage on my part 🤔 .

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dsherretcommented, Jul 20, 2020

@jasonkuhrt ok, this is fixed and published in 7.1.3. Thanks for reporting it!

1reaction
dsherretcommented, Jul 20, 2020

For debugging this, it would be good to use the @ts-morph/bootstrap example I gave and then figure out where in the typescript compiler it creates the diagnostic then work back from there to figure out why that’s happening. I can look at this later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Document --incremental and composite project APIs #31849
I don't see a difference ; so I assume that the incremental build info isn't used at all (although written). Another observation: In...
Read more >
How can I use --incremental from TypeScript compiler API?
You will need to create a program using the ts. createIncrementalProgram function. For example: import * as ts from "typescript"; const program ...
Read more >
Announcing TypeScript 3.6 - Microsoft Developer Blogs
For leveraging project references, a new createSolutionBuilder function has been exposed, which returns an instance of the new type ...
Read more >
Overview - TypeScript
For leveraging project references, a new createSolutionBuilder function has been exposed, which returns an instance of the new type SolutionBuilder .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found