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.
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.”
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).
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?
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.
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.
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?
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.
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):
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.