cevek / ttypescript

Over TypeScript tool to use custom transformers in the tsconfig.json
1.53k stars 56 forks source link

ttsc -watch crashing when regenerating files #92

Open oaosman84 opened 4 years ago

oaosman84 commented 4 years ago

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.
cevek commented 3 years ago

@oaosman84 Do you have any repro project?

trungda commented 3 years ago

I am encountering the same issue

Val-istar-Guo commented 3 years ago

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)
nonara commented 3 years ago

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.

Val-istar-Guo commented 3 years ago

@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

nonara commented 3 years ago

@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 commented 3 years ago

@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!

Val-istar-Guo commented 3 years ago

@nonara Unfortunately, the error did not go away

***/node_modules/typescript/lib/typescript.js:14332
 :ts.skipTrivia(sourceFile.text, errorNode.pos);

TypeError: Cannot read property 'text' of undefined

Operating procedures

nonara commented 3 years ago

@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.