ttypescript icon indicating copy to clipboard operation
ttypescript copied to clipboard

ttsc -watch crashing when regenerating files

Open oaosman84 opened this issue 4 years ago • 9 comments

Hey, We use ttsc -watch, and when I regenerate some files (using Apollo's code type generator), the compiler crashes. Though the stack trace is coming from typescript, this doesn't seem to happen with normal tsc - watch.

[11:25:24 AM] File change detected. Starting incremental compilation...


/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:2121
                fail("Expected " + a + " <= " + b);
                ^
Error: Debug Failure. Expected 2511 <= 2502
    at Object.assertLessThanOrEqual (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:2121:17)
    at Object.createFileDiagnostic (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:16725:22)
    at createDiagnosticForNodeInSourceFile (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:10590:19)
    at Object.createDiagnosticForNode (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:10580:16)
    at error (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:33795:22)
    at resolveExternalModule (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:35446:25)
    at resolveExternalModuleNameWorker (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:35363:19)
    at resolveExternalModuleName (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:35358:20)
    at getSymbolAtLocation (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:63620:32)
    at Object.getSymbolAtLocation (/Users/osmanosman/Developer/apps/packages/common/node_modules/typescript/lib/typescript.js:33312:31)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

oaosman84 avatar May 09 '20 18:05 oaosman84

@oaosman84 Do you have any repro project?

cevek avatar Sep 07 '20 09:09 cevek

I am encountering the same issue

trungda avatar Oct 16 '20 04:10 trungda

ttsc --watch will throw error,But tsc not throw

same issue:

           : ts.skipTrivia(sourceFile.text, errorNode.pos);
                                       ^
TypeError: Cannot read property 'text' of undefined
    at getErrorSpanForNode (/report/node_modules/typescript/lib/typescript.js:13660:40)
    at createDiagnosticForNodeInSourceFile (/report/node_modules/typescript/lib/typescript.js:13564:20)
    at Object.createDiagnosticForNode (/report/node_modules/typescript/lib/typescript.js:13555:16)
    at error (/Users/shein/report/node_modules/typescript/lib/typescript.js:43205:22)
    at resolveExternalModule (/report/node_modules/typescript/lib/typescript.js:45212:25)
    at resolveExternalModuleNameWorker (/report/node_modules/typescript/lib/typescript.js:45129:19)
    at resolveExternalModuleName (/report/node_modules/typescript/lib/typescript.js:45124:20)
    at checkImportDeclaration (/report/node_modules/typescript/lib/typescript.js:74645:49)
    at checkSourceElementWorker (/report/node_modules/typescript/lib/typescript.js:75078:28)
    at checkSourceElement (/report/node_modules/typescript/lib/typescript.js:74911:17)

Val-istar-Guo avatar Nov 13 '20 09:11 Val-istar-Guo

Not sure what's happening here, but here's my 2 cents from my own experience and reports from others.

Generally these types of errors come from modifying nodes incorrectly. In other words not using the API - ie. directly modifying properties, replacing nodes by assignment, etc. We can sometimes get away with hacks like that during a one-shot transformation, but watch mode actively maintains the AST and all of the trivia and diagnostics associated. Circumventing the API causes it to break down as its references are mismatched.

If either of you can create a minimal reproduction, I'd be happy to have a look.

nonara avatar Nov 15 '20 21:11 nonara

@nonara I found my problem because of the use of typescript-transform-paths@2 version.typescript-transform-paths@1 is running normally, it should be a typescript-transform-paths problem.

https://github.com/LeDDGroup/typescript-transform-paths/issues/72

Val-istar-Guo avatar Nov 16 '20 05:11 Val-istar-Guo

@Val-istar-Guo Haha. Yep, that'd do it then. We're using a workaround which directly replaces a node due to a TS compiler issue. Really hoping TS fixes the upstream issue so I can close that. I'm monitoring closely. If TS doesn't fix it by v4.2.0, I'll find another way or do a PR on TS.

Meanwhile, I suggest using v1 for now and follow that issue.

nonara avatar Nov 17 '20 00:11 nonara

@Val-istar-Guo I had some time to dig into the new compiler API, and I believe the issue should be resolved. If you have a chance to try v2.0.3, I'd appreciate it if you let me know if it works for you!

nonara avatar Nov 17 '20 06:11 nonara

@nonara Unfortunately, the error did not go away

  • "typescript-transform-paths": "^2.0.3"
  • "ttypescript": "^1.5.12",
  • "typescript": "^4.1.2",
  • "typescript-nestjs-swagger-plugin": "^1.1.0",
***/node_modules/typescript/lib/typescript.js:14332
 :ts.skipTrivia(sourceFile.text, errorNode.pos);

TypeError: Cannot read property 'text' of undefined

Operating procedures

  • ttsc --watch
  • change some ts file that be watched
  • The error throw

Val-istar-Guo avatar Nov 21 '20 05:11 Val-istar-Guo

@Val-istar-Guo thanks for following up. There may not be anything that we can do until TS fixes the upstream. Would you mind filing an issue with the problem and repro steps on the GH issues for typescript-transform-paths?

When you do, I'll look into it and you can track what's going on there.

nonara avatar Nov 22 '20 04:11 nonara