Unable to Start SonarTS - Typescript not found

  • Version:
    SonarLint 4.6
    Typescript: 3.7.5
    Node: 12.16.2

  • Error observed: Cannot find typescript. Even though it is installed globally as well as in the local project.

Starting SonarTS Server
internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module 'typescript/package.json'
Require stack:
- /Users/jt044c/Library/Caches/JetBrains/IntelliJIdea2020.1/tmp/sonarlint/.sonartmp_8299451258334165138/10126847783763295567/sonarts-bundle/node_modules/tslint-sonarts/lib/runner/sonartsServer.js
- /Users/jt044c/Library/Caches/JetBrains/IntelliJIdea2020.1/tmp/sonarlint/.sonartmp_8299451258334165138/10126847783763295567/sonarts-bundle/node_modules/tslint-sonarts/bin/sonarts-server
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at logTypeScriptMetaInfo (/Users/jt044c/Library/Caches/JetBrains/IntelliJIdea2020.1/tmp/sonarlint/.sonartmp_8299451258334165138/10126847783763295567/sonarts-bundle/node_modules/tslint-sonarts/lib/runner/sonartsServer.js:119:21)
    at SonarTsServer.start (/Users/jt044c/Library/Caches/JetBrains/IntelliJIdea2020.1/tmp/sonarlint/.sonartmp_8299451258334165138/10126847783763295567/sonarts-bundle/node_modules/tslint-sonarts/lib/runner/sonartsServer.js:39:9)
    at Object.<anonymous> (/Users/jt044c/Library/Caches/JetBrains/IntelliJIdea2020.1/tmp/sonarlint/.sonartmp_8299451258334165138/10126847783763295567/sonarts-bundle/node_modules/tslint-sonarts/bin/sonarts-server:6:15)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/jt044c/Library/Caches/JetBrains/IntelliJIdea2020.1/tmp/sonarlint/.sonartmp_8299451258334165138/10126847783763295567/sonarts-bundle/node_modules/tslint-sonarts/lib/runner/sonartsServer.js',
    '/Users/jt044c/Library/Caches/JetBrains/IntelliJIdea2020.1/tmp/sonarlint/.sonartmp_8299451258334165138/10126847783763295567/sonarts-bundle/node_modules/tslint-sonarts/bin/sonarts-server'
  ]
}
Failed to start SonarTS Server
java.net.SocketTimeoutException: Accept timed out
	at java.base/java.net.PlainSocketImpl.socketAccept(Native Method)
	at java.base/java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:458)
	at java.base/java.net.ServerSocket.implAccept(ServerSocket.java:565)
	at java.base/java.net.ServerSocket.accept(ServerSocket.java:533)
	at org.sonar.plugin.typescript.ContextualServer.startSonarTSServer(ContextualServer.java:118)
	at org.sonar.plugin.typescript.ContextualServer.start(ContextualServer.java:92)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.sonarsource.sonarlint.shaded.org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
	at org.sonarsource.sonarlint.shaded.org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89)
	at org.sonarsource.sonarlint.core.container.ComponentContainer$1.start(ComponentContainer.java:271)
	at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
	at org.sonarsource.sonarlint.shaded.org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
	at org.sonarsource.sonarlint.shaded.org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
	at org.sonarsource.sonarlint.shaded.org.picocontainer.behaviors.Stored.start(Stored.java:110)
	at org.sonarsource.sonarlint.shaded.org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
	at org.sonarsource.sonarlint.shaded.org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
	at org.sonarsource.sonarlint.shaded.org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
	at org.sonarsource.sonarlint.core.container.ComponentContainer.startComponents(ComponentContainer.java:124)
	at org.sonarsource.sonarlint.core.container.storage.StorageContainer.doAfterStart(StorageContainer.java:126)
	at org.sonarsource.sonarlint.core.container.ComponentContainer.startComponents(ComponentContainer.java:125)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.start(ConnectedSonarLintEngineImpl.java:118)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.lambda$update$2(ConnectedSonarLintEngineImpl.java:176)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.withRwLock(ConnectedSonarLintEngineImpl.java:325)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.update(ConnectedSonarLintEngineImpl.java:169)
	at org.sonarlint.intellij.tasks.ServerUpdateTask.run(ServerUpdateTask.java:97)
	at org.sonarlint.intellij.tasks.ServerUpdateTask$2.run(ServerUpdateTask.java:84)
	at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:930)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsync$5(CoreProgressManager.java:432)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$null$3(ProgressRunner.java:233)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:164)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:625)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:570)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:151)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:233)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

Workaround:None

Hello, thank you for your feedback.

It looks like SonarLint is trying to load an old version of the TypeScript analyzer, and failing to use the embedded typescript compiler.

Are you using connected mode? If so, which version of SonarQube and SonarTS are you using?

Using

SonarQube: 7.9.1
SonarTS: 1.8

Great, thank you for this additional information.

I managed to reproduce the issue and opened a pull request with a change that seems to fix the issue; could you please manually install this snapshot version to check whether it fixes the issue on your machine?

Furthermore, you might want to update SonarQube and installed analyzers: SonarQube 7.9 LTS is 8 months old already, and it comes with the latest and greatest JavaScript and TypeScript analyzers.

Hi Jean,

The snapshot version worked just fine! Thank you!

As far as the versions for SonarQube and SonarTS, unfortunately our organization is pretty big and that is something out of my reach. I know we are updating to SonarTS 1.9 but that’s about it.

Thanks for the confirmation, we’ll make sure that the change is part of the next release.

FYI, SonarLint for IntelliJ 4.7 has just been released, including the fix for this issue.