JavaScript heap out of memory when analysing Typescript

Hello,

I am using an onsite SonarQube server version 7.9.2 (Enterprise) and I am trying to analyse a set of Typescript files on our Teamcity CI using the SonarQube runner, but the analysis fails with the following error:

 06:31:13.798 DEBUG: Starting external process `node --max-old-space-size=2048 C:\Bwork\a98d7be0f1403d60\.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\bin\tsrunner`
 06:32:08.836 ERROR: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 06:32:08.836 ERROR: 
 06:32:09.034 ERROR: Writing Node.js report to file: report.20200904.063208.4772.0.001.json
 06:32:09.034 ERROR: Node.js report completed
 06:32:09.069 ERROR:  1: 00007FF74236232F napi_wrap+124543
 06:32:09.069 ERROR:  2: 00007FF7423036A6 public: bool __cdecl v8::base::CPU::has_sse(void)const __ptr64+34502
 06:32:09.070 ERROR:  3: 00007FF742304366 public: bool __cdecl v8::base::CPU::has_sse(void)const __ptr64+37766
 06:32:09.070 ERROR:  4: 00007FF742B08C5E private: void __cdecl v8::Isolate::ReportExternalAllocationLimitReached(void) __ptr64+94
 06:32:09.070 ERROR:  5: 00007FF742AF0CA1 public: class v8::SharedArrayBuffer::Contents __cdecl v8::SharedArrayBuffer::Externalize(void) __ptr64+833
 06:32:09.070 ERROR:  6: 00007FF7429BE56C public: static void __cdecl v8::internal::Heap::EphemeronKeyWriteBarrierFromCode(unsigned __int64,unsigned __int64,class v8::internal::Isolate * __ptr64)+1436
 06:32:09.070 ERROR:  7: 00007FF7429C9910 public: void __cdecl v8::internal::Heap::ProtectUnprotectedMemoryChunks(void) __ptr64+1312
 06:32:09.070 ERROR:  8: 00007FF7429C6444 public: static bool __cdecl v8::internal::Heap::PageFlagsAreConsistent(class v8::internal::HeapObject)+3204
 06:32:09.071 ERROR:  9: 00007FF7429BBCD3 public: bool __cdecl v8::internal::Heap::CollectGarbage(enum v8::internal::AllocationSpace,enum v8::internal::GarbageCollectionReason,enum v8::GCCallbackFlags) __ptr64+1283
 06:32:09.071 ERROR: 10: 00007FF7429BA4A4 public: void __cdecl v8::internal::Heap::AddRetainedMap(class v8::internal::Handle<class v8::internal::Map>) __ptr64+2356
 06:32:09.071 ERROR: 11: 00007FF7429DB775 public: class v8::internal::Handle<class v8::internal::HeapObject> __cdecl v8::internal::Factory::NewFillerObject(int,bool,enum v8::internal::AllocationType) __ptr64+53
 06:32:09.071 ERROR: 12: 00007FF7427478D7 ??4iterator@JumpTableTargetOffsets@interpreter@internal@v8@@QEAAAEAV01234@$$QEAV01234@@Z+3687
 06:32:09.071 ERROR: 13: 00007FF742F3463D public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+567949
 06:32:09.071 ERROR: 14: 0000018D3E964195 
 06:32:09.078 INFO: ------------------------------------------------------------------------
 06:32:09.078 INFO: EXECUTION FAILURE
 06:32:09.078 INFO: ------------------------------------------------------------------------
 06:32:09.078 INFO: Total time: 2:51:51.557s
 06:32:09.254 ERROR: Error during SonarQube Scanner execution
 java.lang.IllegalStateException: Failed to run external process `node --max-old-space-size=2048 C:\Bwork\a98d7be0f1403d60\.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\bin\tsrunner`. Run with -X for more information
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.executeExternalRunner(ExternalTypescriptSensor.java:256)
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.analyze(ExternalTypescriptSensor.java:130)
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.execute(ExternalTypescriptSensor.java:111)
 	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
 06:32:09.254 INFO: Final Memory: 55M/1837M
 	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
 06:32:09.254 INFO: ------------------------------------------------------------------------
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 06:32:09.254 DEBUG: Execution getVersion
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 06:32:09.256 DEBUG: Execution stop
 	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:400)
 	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
 	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
 	at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:99)
 	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 	at java.lang.reflect.Method.invoke(Method.java:498)
 	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
 	at com.sun.proxy.$Proxy0.execute(Unknown Source)
 	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
 	at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
 	at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
 	at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
 	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
 Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 2 column 1 path $
 	at com.google.gson.Gson.fromJson(Gson.java:891)
 	at com.google.gson.Gson.fromJson(Gson.java:817)
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.executeExternalRunner(ExternalTypescriptSensor.java:247)
 	... 32 more
 Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 2 column 1 path $
 	at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:351)
 	at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:70)
 	at com.google.gson.Gson.fromJson(Gson.java:879)
 	... 34 more
 06:32:09.254 ERROR: 
 06:32:09.254 ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
 Process exited with code 1

Plugin version: SonarTS 1.9.0.3766
Scanner version: 3.0.3.778

I am also trying to upload Typescript Linting and stylelint reports (using sonar.typescript.tslint.reportPaths and sonar.css.stylelint.reportPaths), I tried to disable those but with the same result as above.

I tried setting the NODE_OPTIONS variable to provide node more memory but that is apparently ignored by the plugin.
What am I missing?

Hi,

we have a similar issue on our Jenkins-based build factory. Outofmemory error when running the JavaScript / TypeScript analysis, which prevents the ts files from being scanned.
All the other files in the project are scanned appropriately. I would be very interrested in a way to either investigate further, or to provide more memory to the build.

In our case the log says:

21:47:45  INFO: Sensor SonarTS [typescript]
21:47:45  INFO: Analyzing 50 typescript file(s) with the following configuration file ${tsconfigpath}\tsconfig.json
21:48:18  ERROR: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
21:48:18  ERROR:  1: 00007FF721C6F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
21:48:18  ERROR:  2: 00007FF721C4A0C6 node::MakeCallback+4518
21:48:18  ERROR:  3: 00007FF721C4AA30 node_module_register+2032
21:48:18  ERROR:  4: 00007FF721ED20EE v8::internal::FatalProcessOutOfMemory+846
21:48:18  ERROR:  5: 00007FF721ED201F v8::internal::FatalProcessOutOfMemory+639
21:48:18  ERROR:  6: 00007FF7223F2BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
21:48:18  ERROR:  7: 00007FF7223E9C46 v8::internal::ScavengeJob::operator=+24310
21:48:18  ERROR:  8: 00007FF7223E829C v8::internal::ScavengeJob::operator=+17740
21:48:18  ERROR:  9: 00007FF7223F0F87 v8::internal::Heap::MaxHeapGrowingFactor+2327
21:48:18  ERROR: 10: 00007FF7223F1006 v8::internal::Heap::MaxHeapGrowingFactor+2454
21:48:18  ERROR: 11: 00007FF721FACDB7 v8::internal::Factory::NewFillerObject+55
21:48:18  ERROR: 12: 00007FF722042CC6 v8::internal::WasmJs::Install+29414
21:48:18  ERROR: 13: 000002BD0BDDC5C1 
21:48:18  ERROR: External process `node --max-old-space-size=2048 ${project_base_path}.sonarqube\out\.sonar\mod4\sonarts-bundle\node_modules\tslint-sonarts\bin\tsrunner` returned an empty output. Run with -X for more information
21:48:18  INFO: Sensor SonarTS [typescript] (done) | time=29526ms

Thanks

Thanks

We just updated a range of plugins on our SonarQube server and now the analysis passes, although it takes significantly longer now.

The SonarTS plugin was updated from 1.9 to 2.1 e.g. and now analysis of TS files runs fine. Now it’s just the Java analysis which takes hours, maybe we need to tune our settings though.

Maybe that works for you as well @Vincent_Klock.

Thanks Sebastian, I checked and we are running version 1.9 as well. Will give it a try.