How to add local node and npm binary to PATH only in PhpStorm?

I have the following situation:

- Windows 11 is used
- NodeJS and npm are in a subfolder of the project
- the interpreter is correctly configured in the settings as local file paths
- NodeJS is not globally installed to prevent conflicts between different projects
- node and npm are not available as commands in the terminal  in PhpStorm

I see only an option as checkbox to add the PHP interpreter to the PATH variable in the project. But so far I see no setting to do the same for NodeJS. How can this be done on a per-project basis without touching my PATH variable on Windows outside of PhpStorm?

0

Hi there,

To be used in the built-in Terminal?

There is an "Environment variables" field on “Settings/Preferences | Tools | Terminal”. 

Seems to work OK for me, at least when cmd.exe shell is used.

0

I'm not sure how to prepend smething to PATH there. Can you explain this in detail? I'm not speaking about adding some extra variable NODE. I just want to add the path of the NodeJS binary to the PATH variable.

The PhpStorm documentation is not very helpful here.

0

Hi there,

It's a simple shell logic – you just need to know how the environment variables work in general + PATH in particular (how to list multiple paths in a single line). You will be adding a path to the folder where your shell / OS will be looking for the executable files and not the path for a specific executable file.

PhpStorm interface is very easy to use here IMO (at very least I have no complaints on this aspect).

Here is what I was using for my test (used different PHP version, since I only have one Node, and it is a system-wide installation)

1

Thanks, that was very helpful. Since I normally do not work with Windows, this was a bit new to me, that I can do that there.

0

This doesn't seem to work as expected in 2024.2, the %PATH% part is not expanded in the current version of PhpStorm. That means many commands fail now.

0

Still seems to work OK for me here.

Are you using new terminal in PhpStorm? If so – see if disabling it (and restarting the IDE afterwards) will do any better.

0

I'm using the old terminal.

0

> %PATH% part is not expanded in the current version of PhpStorm. That means many commands fail now.

Could you please provide more details on what exactly happens?

Also, is there a particular reason for such a configuration with per-project Node.js installation? It looks like nvm would be a suitable solution.

0

What happens, when I use %PATH% in the setting: the other commands from my PATH variable do not work anymore.

I have a nodejs folder just in the project. Node is not globally installed and not planned to be.

Yes, we have different branches with different Nodejs versions and this is some very old codebase, the team is not experienced with nvm and nodenv.

0

Could you please share a screenshot of your terminal settings (Settings > Tools > Terminal)?

> when I use %PATH% in the setting: the other commands from my PATH variable do not work anymore.

Could you please elaborate on that? What kind of commands and where do they not work?

 

 

 

 

 

0

Commands from the orignal PATH variable do not work, when I enter it like here on Windows 11: https://intellij-support.jetbrains.com/hc/en-us/community/posts/20539507767954/comments/20577662230674

Because of that I had to manually append the original PATH content:


Without that, commands like docker do not work.

C:\PPV13\nodejs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\PowerShell\7\;C:\Users\DanielRuf\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\JetBrains\PhpStorm 2024.1.4\bin;

If I change that to C:\PPV13\nodejs;%PATH% I get docker: command not found: “docker : Die Benennung "docker" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines ausführbaren Programms erkannt. ”

Only with the long version C:\PPV13\nodejs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\PowerShell\7\;C:\Users\DanielRuf\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\JetBrains\PhpStorm 2024.1.4\bin; it works.

My current terminal settings are these:

 

0

D Ruf 

This must be because you are using powershell while I'm using cmd.exe (as stated in my very first comment).

 

Please switch the “Shell path” to cmd.exe – any better?

It works fine for me there and does not if I switch to the bundled Windows powershell.exe (which is v5.1 or so – you can use $PSVersionTable.PSVersion to check that).

At the same time it works fine again if I use the separately/manually installed PowerShell Core 7.

0

Interesting, I had to change it twice, because my new terminal sessions still used powershell v5 after changing the setting as described (clicking “apply” and starting a new terminal window).

Now it works, thank you.

0

Doesn't seem to work with pwsh.exe. The other binaries are still missuing when I use “C:\PPV13\nodejs;%PATH%”.

I'm not sure if this is a bug in combination with Powershell or if it is not supported by Powershell. Normally I don't work on a Windows machine so this is unknown to me.

0

D Ruf 

I should have tested other tools (e.g. my system node) before stating that it all works. I've only tested my php -v output (if it overwrites what PhpStorm sets or not).

 

The thing is: the %PATH% reference is interpreted (evaluated and replaced at runtime) by the actual cmd.exe shell. The PowerShell (both Windows and Core) does not use that syntax. If you execute $env:Path in your powershell session, it will have the literal %PATH% there and not the “expanded” value as cmd.exe would do.

Sadly, I do not know the proper solution here for PowerShell (how to reference the default/system PATH when adding your own path via shell environment variable without hardcoding like you did).

 

The best I can suggest right now, is to set the env variable during the actual terminal session by executing the command when the session starts (which is inconvenient and easy to forget obviously):

$env:Path = "C:\PPV13\nodejs;" + $env:Path

Or stick to the cmd.exe shell where such a variable expanding works.

0

请先登录再写评论。