microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.08k stars 12.5k forks source link

Debug Failure. False expression: Expected isNewFile for (only) new files #27867

Closed amcasey closed 5 years ago

amcasey commented 6 years ago

We have occurrences from 3.0.0-dev to 3.2.0-dev. Here's a stack from 3.1.3:

Error processing request. Debug Failure. False expression: Expected isNewFile for (only) new files
Verbose Debug Information: {"isNewFile":false,"hasScriptInfo":false}
Error: Debug Failure. False expression: Expected isNewFile for (only) new files
Verbose Debug Information: {"isNewFile":false,"hasScriptInfo":false}
    at mapTextChangesToCodeEdits (tsserver.js:123151:22)
    at IOSession.Session.mapTextChangeToCodeEdit (tsserver.js:122984:24)
    at tsserver.js:122981:73
    at Array.map (<anonymous>)
    at IOSession.Session.mapTextChangesToCodeEdits (tsserver.js:122981:36)
    at IOSession.Session.mapCodeFixAction (tsserver.js:122977:84)
    at tsserver.js:122930:96
    at Array.map (<anonymous>)
    at IOSession.Session.getCodeFixes (tsserver.js:122930:55)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (tsserver.js:121789:61)
    at tsserver.js:123086:88
    at IOSession.Session.executeWithRequestId (tsserver.js:123077:28)
    at IOSession.Session.executeCommand (tsserver.js:123086:33)
    at IOSession.Session.onMessage (tsserver.js:123106:35)
    at Interface.<anonymous> (tsserver.js:124369:27)
    at emitOne (events.js:116:13)
    at Interface.emit (events.js:211:7)
    at Interface._onLine (readline.js:282:10)
    at Interface._normalWrite (readline.js:424:12)
    at Socket.ondata (readline.js:141:10)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)
ghost commented 6 years ago

Is that the wrong stack trace? The diagnostic "Expected isNewFile for (only) new files" should only happen in mapTextChangesToCodeEdits, not tryResuseStructureFromOldProgram.

amcasey commented 6 years ago

Quite possibly - I've been looking at several. Let me confirm.

amcasey commented 6 years ago

Fixed - sorry about that.

Hexcles commented 6 years ago

I'm seeing this error from tsserver in my editor (Vim with YCM) (with almost the same stacktrace) when I have import fs = require('fs'); style import in my Node project (target=es2017, everything else is the default). Switching to const fs = require('fs') makes the error go away.

Hexcles commented 6 years ago

I just found out it only happened when I used import = require style import on a module without type annotations, but this still looks like a bug -- it shouldn't crash the server. tsc is still able to tell me to try npm install @types/..., among other errors.

ghost commented 6 years ago

@Hexcles I'm not able to reproduce this crash using that repro in typescript@next. I'm testing in a directory that consists of just these files: a.ts:

import fs = require('fs');

tsconfig.json:

{
    "compilerOptions": {
        "target": "es2017"
    }
}

I've also tested with @types/node installed but still didn't see a crash. I assume you're also seeing a diagnostic Import assignment cannot be used when targeting ECMAScript modules. given those compiler options.

Hexcles commented 6 years ago

Looking at my tsconfig.json again there's also module: "commonjs" which prevents the warning about the import assignment.

However, I can't reproduce the issue any more, either. I'm not sure if my tsc installation was updated recently. Looks like you initially found the issue from telemetry so you might be able to look at stats to see if the problem has indeed disappeared in recent versions.

tim-phillips commented 5 years ago

I get the same error on 3.3.0-dev (using YouCompleteMe):

Debug Failure. Expected isNewFile for (only) new files. {"isNewFile":false,"hasScriptInfo":false}

Error: Debug Failure. Expected isNewFile for (only) new files. {"isNewFile":false,"hasScriptInfo":false}
    at IOSession.Session.mapTextChangeToCodeEdit (/Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125567:30)
    at /Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125559:73
    at Array.map (<anonymous>)
    at IOSession.Session.mapTextChangesToCodeEdits (/Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125559:36)
    at IOSession.Session.mapCodeFixAction (/Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125555:84)
    at /Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125508:96
    at Array.map (<anonymous>)
    at IOSession.Session.getCodeFixes (/Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125508:55)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (/Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:124313:61)
    at /Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125676:88
    at IOSession.Session.executeWithRequestId (/Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125667:28)
    at IOSession.Session.executeCommand (/Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125676:33)
    at IOSession.Session.onMessage (/Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:125698:35)
    at Interface.<anonymous> (/Users/development/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/lib/tsserver.js:126958:27)
    at Interface.emit (events.js:182:13)
    at Interface._onLine (readline.js:290:10)
    at Interface._normalWrite (readline.js:433:12)
    at Socket.ondata (readline.js:149:10)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

I don't get the error when there is no import statement, but as soon as I add import React from 'react' or const react = require('react') then it errors.

tim-phillips commented 5 years ago

I installed Visual Studio Code and it somehow fixed this issue for me in vim/ycm.

sheetalkamat commented 5 years ago

Closing this as it seems fixed in recent build. @amcasey please reopen if this repros in newer builds.

amcasey commented 5 years ago

I see recent hits for getEditsForFileRename, getEditsForRefactor, and getCodeFixes in 3.3.0-dev, 3.3.0-dev.20190101, and 3.3.0-dev.20190108.

sheetalkamat commented 5 years ago

@amcasey I think https://github.com/Microsoft/TypeScript/pull/26280 should also fix it. So if any reports of this after 3.3.0-dev.20190109 would qualify for reinvestigation.

adammenges commented 5 years ago

I currently see this in Atom with atom-typescript:

screen shot 2019-02-09 at 5 02 20 pm
⇒  tsc --version
Version 3.3.3
sheetalkamat commented 5 years ago

@adammenges Can you please share the tssever log of the issue? Thanks.

sheetalkamat commented 5 years ago

@adammenges Please provide complete tsserver log for us to be able to investigate this futher. Thanks. We will open this again when we have more information. Thanks