NodeJS Executable not found by SonarLint PyCharm Plugin

Hi,

I am using the SonarLint plugin 4.6.0.16682 in PyCharm 2020.1 Professional (Build #PY-201.6668.115) on MacOS 10.15.4 connected to a project in a SonarQube 7.9.2 Enterprise Edition server.

  1. I installed Node.JS 13.13.0 via nvm. When I opened my project in PyCharm, I was notified that “Node.js >= 8.x is required to perform JavaScript or TypeScript analysis.”
  2. Assuming that SonarLint does not get to see the PATH constructed by nvm, I additionally installed NodeJS 13.13.0 via brew in /usr/local. The result was the same, even after a restart of PyCharm (and logout and re-login at the OS-level).
  3. Following a comment in the post “SonarLint stops detecting issues after binding to a server”, I tried to set the analysis property sonar.nodejs.executable in the plugin configuration. But the property was always dropped again (because the project is connected and this property is not set on the server???).

The SonarLint logs were the same following all attempts. Unfortunately, they do not include the PATH searched for the executable. What am I missing? Where or how do I need to install Node.JS (or which version thereof) for SonarLint to find it?

Regards,
Christoph

Logs:

sonarlint-log.txt (19.7 KB)

Plugins installed on the server:

Name Version
Dependency-Check 2.0.2
Flutter 0.2.0
FxCop 1.4.1
Git 1.8 (build 1574)
GitHub Authentication for SonarQube 1.5 (build 870)
Groovy 1.6
JaCoCo 1.0.2 (build 475)
LDAP 2.2 (build 608)
License for SonarLint 7.9 (build 30863)
Perl 0.4.6
SAML 2.0 Authentication for SonarQube 1.1.0 (build 181)
SonarABAP 3.8 (build 2034)
SonarApex 1.5.0 (build 315)
SonarC# 7.15 (build 8572)
SonarCFamily 6.3 (build 11371)
SonarCOBOL 4.4 (build 3403)
SonarCSS 1.1.1 (build 1010)
SonarFlex 2.5.1 (build 1831)
SonarGo 1.1.1 (build 2000)
SonarHTML 3.1 (build 1615)
SonarJS 5.2.1 (build 7778)
SonarJava 5.13.1 (build 18282)
SonarKotlin 1.5.0 (build 315)
SonarPHP 3.2.0.4868
SonarPLI 1.10 (build 1880)
SonarPLSQL 3.4.1 (build 2576)
SonarPython 1.14.1 (build 3143)
SonarQube License Check Plugin 3.1.1
SonarRPG 2.3 (build 1187)
SonarRuby 1.5.0 (build 315)
SonarScala 1.5.0 (build 315)
SonarSwift 4.1 (build 3087)
SonarTS 1.9 (build 3766)
SonarTSQL 1.4 (build 3334)
SonarVB 7.15 (build 8572)
SonarVB6 2.6 (build 1875)
SonarXML 2.0.1 (build 2020)
Svn 1.9.0.1295
Vulnerability Analysis 7.9 (build 5105)
Vulnerability Rules for C# 7.9 (build 5105)
Vulnerability Rules for Java 7.9 (build 5105)
Vulnerability Rules for PHP 7.9 (build 5105)

Hello, thank you for reporting this issue.

I recall having this issue at some point, because nvm only puts node on the PATH for “login” shells. Did you try to launch PyCharm from a terminal?

I also notice that you are using connected mode with a rather old version of SonarTS, I strongly advise that you update to the latest SonarJS/SonarTS couple if possible: on macOS, the newer versions use the run-node utility to reliably find the Node runtime.

Hi,

thanks for your reply.

Indeed, the way I launch PyCharm seems to make a difference. I usually start PyCharm via JetBrain’s Toolbox (i.e., no shell terminal). Triggered by your question, I restarted PyCharm using the shell script generated by the Toolbox App (which is a very simple wrapper around open -a "/absolute/path/to/the/executable/pycharm" "$@") and this time SonarLint did find the node executable. I cannot be sure without further experiments whether it found the node installed by nvm or the one installed by brew as /usr/local/bin/node - but I assume it is the former because its installation directory appears first in my shell’s PATH.

However, I had assumed that SonarLint started via the Toolbox would at least find the executable in /usr/local/bin. Or that I can somehow explicitly point the plugin to the executable on my local machine. Using any properties from the server would obviously not make sense here and relying on PATH if the value of PATH is not easy to control depending on how PyCharm was started is less than ideal…

You mention the versions of SonarJS/SonarTS. It is my understanding that the version used locally depends on whatever is installed on the server, doesn’t it? I will ask the colleagues who operate the server whether they can upgrade the plugins. However, server-side upgrades usually need to be planned; there’s a reason why we have the Enterprise Edition. :slight_smile:

Cheers,
Christoph

1 Like

Hi,

just a brief addition: The PATH in the environment of the Toolbox and then inherited by PyCharm when invoked via the Toolbox App is /usr/bin:/bin:/usr/sbin:/sbin. This explains why none of the node executables on my system are by SonarLint. Changing the environment of applications started via the Finder is messy, to say the least, applies indiscriminately to all applications started by the Finder, and might not even be effective for for PATH. Changes to the Toolbox’s Info.plist would most likely be overwritten by the next upgrade. For me the workaround will therefore be to start this particular PyCharm project from a shell terminal.

Given that the “official” Node.JS macOS installer places the binary in /usr/local/bin as well, I wonder how SonarLint can find node on your machine unless you start PyCharm from a shell where node is in the PATH?

Regards,
Christoph

Newer versions of JS and TS analyzers use run-node, which does its best to locate node wherever it can be on developer boxes.

This being said, I kind of agree that a publicly available property in SonarLint or in the analyzers would provide a more predictable user experience.

Understood, and I already submitted the ticket to our dev infrastructure team asking for an upgrade of the SonarTS / Sonar JS plugins. This might take a while, though, because changes to the shared infrastructure need to be coordinated.

Fortunately, starting PyCharm from the terminal shell is a viable workaround for the time being.

2 Likes

Hi,

I think that @ludwigc advice worked for me (nvm & IntelliJ Idea 2020.2).

After configuring the path manually here, the error is not showing anymore! yay!

which node to get the current path. Hope it helps other people

2 Likes

Thank you @funder7, your comment help me solve this issue after upgrading phpStorm 2020.3 and getting the same error.

Note that since latest version of SonarLint for IntelliJ (4.12), you have a dedicated setting to configure the Node.js executable path to be used by our analyzer (assuming the auto-detection failed):

1 Like

I added the path as: /home/user/.nvm/versions/node/v14.5.0/bin/node using the new setting but still get the same error of:

SonarLint failed to analyze JavaScript code
		SonarLint requires Node.js runtime version 8.0.0 or later to analyze JavaScript code.
		Please configure the Node.js path in the SonarLint settings.

edit: Restarting PyCharm/Intellij after updating the node setting fixed it.