Skip to content
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

Out of stack space error with tsc 3.0 #26721

Open
Manish3177 opened this issue Aug 28, 2018 · 6 comments
Open

Out of stack space error with tsc 3.0 #26721

Manish3177 opened this issue Aug 28, 2018 · 6 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@Manish3177
Copy link

Manish3177 commented Aug 28, 2018

We have a very large repository of TypeScript code which we recently upgraded from 2.7 to 3.0 (by updating TypeScriptToolsVersion element in all CSPROJs). After this change, we've been seeing occasional compiler crashes with the following stack trace:

>tsc -p tsconfig.json
Script failed with error: 'JsErrorScriptException (0x30001)'.
Out of stack space
Error: Out of stack space
at runWithCancellationToken (Unknown script code:83268:17)
at emit (Unknown script code:83160:13)
at emitFilesAndReportErrors (Unknown script code:86285:9)
at performCompilation (Unknown script code:88050:9)
at executeCommandLine (Unknown script code:88018:17)
at Global code (Unknown script code:88175:1)

>echo %errorlevel%
1

This doesn't occur every time and isn't specific to any project, TS file or the tsconfig file but some projects have a higher failure rate than others. I am unable to share the code being compiled but I don't think that would've been useful anyway because like I said, this isn't happening for anything specific. The best instructions to reproduce I can provide would be:

  1. Open several instances of Visual Studio so that available memory on your system drops below 2 GB.
  2. Run a script that TypeScript compiles several projects / TS files. If that doesn't work...
  3. Run multiple instances of that script simultaneously. A build utility we wrote spawns of number of threads = %NUMBER_OF_PROCESSORS% to go through a long list of tsconfig.json files in various folders as fast as it can and:
    A. It crashes with that error about 90-95% of the times on exact same project.
    B. Compiling that project by itself using the exact same (tsc -p) command line usually works.
    C. It (the script) has been known to crash with that error for multiple projects on occasion.

Based on that, it seems to me that this isn't caused by a specific coding error. It just seems like during the various enhancements that were made during the 2.8, 2.9 or 3.0 releases, one or more code changes are responsible for consuming inappropriately large amount of stack space or something is going overly recursive.

If it were any other error, I think the callstack would've been much deeper but specifically because it was an "out of stack space" error, the callstack is trimmed at runWithCancellationToken function which has a catch block around a call to "func();". AFAICT, "func" is one of the "emitWorker" functions in tsc.js. The error could've originated several levels deep.

I'll be happy to collect more information (by say adding more try..catches in various functions in tsc.js to get a deeper callstack) when the crash occurs next time if someone can provide some guidance on what kind of information can help diagnose the root cause.

Thanks for your help. Please feel to ask any follow up questions you might have.

Search Terms and Related Issue: I searched for "Out of stack space" and found bug reports of compiler crashes but none of them looked like the same issue. #17112 is the closest thing I could find related to this.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Aug 28, 2018
@RyanCavanaugh
Copy link
Member

Just to run through a checklist of things that are commonly a problem, do you have any long-chained expressions like 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 ... in your code? Very "deep" trees like this can cause problems in the emitter because we're recursively stepping in to the binary tree that represents the syntax.

Another thing to try is running with the tsc obtained from npm install -g typescript - the node runtime can sometimes print better stacks, or even succeed where the built-in tsc host fails.

@JTravis76
Copy link

JTravis76 commented Aug 30, 2018

I ran into this same error today. Tried upgrading from 2.8.1 to 3.0.1 and receive the same error:

`Script failed with error: 'JsErrorScriptException (0x30001)'.
Out of stack space
Error: Out of stack space
   at runWithCancellationToken (Unknown script code:83268:17)
   at getSemanticDiagnosticsForFileNoCache (Unknown script code:83275:13)
   at getAndCacheDiagnostics (Unknown script code:83526:13)
   at getSemanticDiagnosticsForFile (Unknown script code:83272:13)
   at Anonymous function (Unknown script code:83220:17)
   at flatMap (Unknown script code:457:17)
   at getDiagnosticsHelper (Unknown script code:83216:13)
   at getSemanticDiagnostics (Unknown script code:83227:13)
   at emitWorker (Unknown script code:83175:21)
   at Anonymous function (Unknown script code:83160:59)`

Working on a Vue.js SPA project using AMD modules when the error hit. tsconfig.json like so:

...    
"rootDir": "./TypeScripts",
    "outFile": "./Scripts/main.js",
    "module": "amd",
    "baseUrl": ".",
    "paths": {
      "vue": [ "typings/vue/index" ],
      "vue-router": [ "typings/vue-router/index" ],
      "vuex": [ "typings/vuex/index" ]
    }

After a bit of trial and error, found that deep nested components was the issue.

Example: Have a component page “Systems”, which is a list of systems the user may edit. The edit button open a System modal (a child component) to view properties. One properties is a list of details of about the “System”, which is a child component. In the details, user may add/edit the detail by opening another model window and that too is a child component.

  • -System
  • --System modal
  • ---System Details
  • ----System Details modal

When I removed the 4th nested component, the TSC complied successfully. However, editing the output.js file, application/components works as expected. The limitation is within Typescript during build process.

Know one option, is to combine the 4th component into the 3rd component.

Could there be any other work-arounds??

@Yglos
Copy link

Yglos commented Sep 21, 2018

We are having same problem. Tried switch from version 2.8 to 3.0.1:

Script failed with error: 'JsErrorScriptException (0x30001)'.
Out of stack space
Error: Out of stack space
 at runWithCancellationToken (Unknown script code:83268:17)
 at emit (Unknown script code:83160:13)
 at emitFilesAndReportErrors (Unknown script code:86285:9)
 at performCompilation (Unknown script code:88050:9)
 at executeCommandLine (Unknown script code:88018:17)
 at Global code (Unknown script code:88175:1)

@Yglos
Copy link

Yglos commented Oct 8, 2018

Same problem with TS 3.1.

@JasonLooney
Copy link

We're also getting this error with 3.x. The error goes away if we remove a bunch of .ts files from a directory that has many of them. Everything compiles fine with version 2.8.3.

@dandrejvv
Copy link

I'm using TypeScript 2.7.2 (because of projects that won't allow me to move to 3), I've gone through a lot of due diligence and even restricted MSBuild to run as version 14 which alleviated it greatly but it is still happening and I have no idea what else to look for to troubleshoot this problem. I'm only getting this problem when I run it as part of a Azure DevOps Pipelines build. I can't seem to replicate it locally no matter how many times I run it. The suggestion of using 2.8.3 brings it up on my local machine immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

6 participants