Skip to content

ProjectService.updateNonInferredProjectFiles - Cannot read property 'path' of undefined #35001

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

Closed
mjbvz opened this issue Nov 8, 2019 · 5 comments
Assignees
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Nov 8, 2019

TypeScript Version: 3.8.0-dev-2019-11-05 and 3.7.2

Search Terms:

  • Untitled file / buffer

Repo
(Tested on windows)

  1. Open the VS Code repo.
  2. Have a single file refactor.ts open: https://github.com/microsoft/vscode/blob/master/extensions/typescript-language-features/src/features/refactor.ts
  3. Reload window to make sure you are in a clean state
  4. Wait for TS to finish loading in refactor.ts
  5. Now create an untitled file (ctrl+n)
  6. Change the language mode of the new file to Typescript (without saving it)

Bug

Cannot read property 'path' of undefined
TypeError: Cannot read property 'path' of undefined
    at ProjectService.updateNonInferredProjectFiles (tsserver.js:137488:43)
    at ProjectService.addFilesToNonInferredProject (tsserver.js:137378:22)
    at ProjectService.updateRootAndOptionsOfNonInferredProject (tsserver.js:137526:22)
    at ProjectService.loadConfiguredProject (tsserver.js:137462:22)
    at ProjectService.createAndLoadConfiguredProject (tsserver.js:137402:22)
    at ProjectService.createLoadAndUpdateConfiguredProject (tsserver.js:137407:36)
    at ProjectService.assignProjectToOpenedScriptInfo (tsserver.js:138230:44)
    at tsserver.js:138461:107
    at Object.mapDefined (tsserver.js:565:30)
    at ProjectService.applyChangesInOpenFiles (tsserver.js:138461:48)
    at Session.handlers.ts.createMapFromTemplate._a.<computed> (tsserver.js:139315:46)
    at tsserver.js:140973:88
    at IOSession.Session.executeWithRequestId (tsserver.js:140964:28)
    at IOSession.Session.executeCommand (tsserver.js:140973:33)
    at IOSession.Session.onMessage (tsserver.js:140996:35)
    at Interface.<anonymous> (tsserver.js:142311:27)
    at Interface.emit (events.js:200:13)
    at Interface._onLine (readline.js:314:10)
    at Interface._normalWrite (readline.js:459:12)
    at Socket.ondata (readline.js:170:10)
    at Socket.emit (events.js:200:13)
    at addChunk (_stream_readable.js:294:12)
    at readableAddChunk (_stream_readable.js:275:11)
    at Socket.Readable.push (_stream_readable.js:210:10)

This seems to be caused by the line

scriptInfo = this.getOrCreateScriptInfoNotOpenedByClientForNormalizedPath(normalizedPath, project.currentDirectory, scriptKind, hasMixedContent, project.directoryStructureHost)!; // TODO: GH#18217

related issues

/cc @sheetalkamat

@mjbvz
Copy link
Contributor Author

mjbvz commented Nov 8, 2019

@RyanCavanaugh Candidate for 3.7.3.

Not a regression since this also repos for me under 3.6.4 but VS Code now treats errors that happen during updateOpen as non-recoverable, which means we restart the TS server.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Nov 8, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.7.3 milestone Nov 8, 2019
@sheetalkamat
Copy link
Member

@mjbvz I don't seem to be able to repro (tsserver.log) with insiders and 3.7.2 or with 3.8 and vscode (tsserver.log)

@sheetalkamat sheetalkamat added the Needs More Info The issue still hasn't been fully clarified label Nov 11, 2019
@mjbvz
Copy link
Contributor Author

mjbvz commented Nov 12, 2019

This is triggered by the tslint extension. A pr came in that changes the working directory using process.chdir (microsoft/typescript-tslint-plugin#39)

When the new file is created, TS Server then ends calling fileExists('tsconfig.json') as part of getConfigFileNameForFile. Normally this returns false but now it returns true since the working directory is different. The the default working directory for me is "/Users/matb", while in the error case the working directory is now "/Users/matb/projects/vscode/extensions/typescript-language-features"

This likely has been happening silently for a while but the new strictness I added means that we now restart the server in this case. I'll look into a fix on the TSlint side.

@sheetalkamat I don't understand why fileExists('tsconfig.json') is called in the first place. It seems like in this case, we always want it to return false?

mjbvz added a commit to microsoft/typescript-tslint-plugin that referenced this issue Nov 12, 2019
@sheetalkamat
Copy link
Member

@mjbvz We need to get the config file for the file being opened, so its walking up the directories to find it...

@sheetalkamat sheetalkamat removed their assignment Nov 12, 2019
@sheetalkamat sheetalkamat added External Relates to another program, environment, or user action which we cannot control. and removed Bug A bug in TypeScript Needs More Info The issue still hasn't been fully clarified labels Nov 12, 2019
@mjbvz
Copy link
Contributor Author

mjbvz commented Nov 12, 2019

But why do we check the relative path tsconfig.json? For on disk files, all calls to this function I saw seem to check absolute paths. For in memory files, do we want to put them into a real tsconfig if possible, meaning their config should be resolved relative to the workspace root?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants