npm is installed using nvm but IntelliJ doesn't know about it

I installed NPM using NVM by following this page : npm throws error without sudo. Everything works perfect in Ubuntu terminal. However, inside IntelliJ terminal, it says I don't have NPM installed. I have tried to set my node interpreter in Language and Framework > Node and NPM to~/.nvm/versions/node/v7.0.0/bin/node I have enabled the Node.js Core library, and from there I can see that npm package is included. But the terminal still say I haven't installed npm. Why?

(I have asked this in StackOverflow already but still cannot figure it out: http://stackoverflow.com/questions/40245370/npm-is-installed-using-nvm-but-intellij-doesnt-know-about-it

 

6
19 comments

NVM patches environment variables on terminal startup only. If the IDE is launched from Terminal, it inherits Terminal environment (including modified PATH environment variable, added NVM_DIR env var, etc). In that case, there are normally no problems with using node/npm, because Idea sees the correct PATH value.
For bash as shell, workaround could be the the following: edit your Idea launcher and set command to "/bin/bash -l -c "/path/to/idea.sh". This command will perform bash login (i.e. reading your .bashrc/.bash_profile files) and after that will run idea

5
Avatar
Permanently deleted user

I typed /opt/idea-IU-162.2032.8/bin/idea.sh in Terminal to launch intelliJ, Is this exactly what you mean by "launching from Terminal"? After that, I still cannot get the same environment variable and Node in intelliJ.

0

Very strange - Idea inherits terminal environment when being started in terminal, so everything should work. What are you doing namely? Can you describe your steps/attach screenshots that show up the issue (npm not recognized in Idea)?

0
Avatar
Permanently deleted user

then intellij is launched.



Node is not found and the PATH is different, how can I make the IntelliJ terminal work like in the first Terminal?

0

Hmm.. Can you attach a screenshot of your terminal settings (Settings | Tools | Terminal) and your idea.log (https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files)?

0

Idea terminal launches a login shell by default, so your .bashrc file is not read. The workaround is adding `-i` parameter to bash in shell path settings. See http://taming-the-bits.logdown.com/posts/275357-how-to-improve-the-terminal-window-in-idea

3
Avatar
Permanently deleted user

Thanks! Adding -i from the terminal setting  actually works. :)

0
Avatar
Permanently deleted user

I had the same problem after IDE update and hated it going out of IDE. My issue was that fish is system shell for my system, and I did not need any config in IDE, but with this release, there was an option added Shell Integration just disable that, and it started working.

 

I got clue be reading the plugin documentation that this option adds one more layer for customization but for my system the whole system is configured hence do not need it.  

 

Disable it, and fish node nvm all started working.

 

Shell integration When this check box is selected, the terminal first loads a custom rc config file (located in the terminal folder under plugins of WebStorm distribution) which provides an additional set-up, and then the user's rc file.
8
Avatar
Permanently deleted user

That is because one of your PATH contains space.

I comment out the line `export PATH="/c/Program Files/erl9.1/bin:$PATH"` and logout login my system, then it works.

This bug was not here in IntellijIdea 2017 but appear in 2018 (2018.2.3)

0
Avatar
Permanently deleted user

I seem to run in a similar problem when starting IntelliJ from the "Jetbrains Toolbox". Node is recognized from the Terminal, however all services in the settings that require NodeJS (like NodeJS and NPM, ESLint, TSLint etc) all can't find the executable (see attached screenshot). 

If I start IntelliJ from the terminal, the executables can be found. In the Terminal settings, I've added `-i` to bash in the shell path, but to no avail. Any ideas how I can get this fixed?

0

When being launched from desktop/System menu, IDE only sees environment variables configured in ~/.profile (login shell), but not in interactive shell configuration files (like ~/.bashhrc). Possible workarounds:

  • Workaround 1: make required variables available in a login shell (i.e. for bash, move them from .bashrc to .bash_profile).
  • Workaround 2: run IDE from a terminal, via bin/idea.sh

see also https://youtrack.jetbrains.com/issue/IDEABKL-7589

> I've added `-i` to bash in the shell path, but to no avail

Terminal preferences (Settings | Tools | Terminal) only affect the built-in terminal

 

3
Avatar
Permanently deleted user

Thanks for your answer. 

In the end I had to add the code that loads NVM to the ~/.profile. When I added it to ~/.bash_profile it didn't seem to change anything, even though it states in the .profile that 

# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
0
Avatar
Permanently deleted user

Add export NVM_SYMLINK_CURRENT=true to your .bashrc before NVM-stuff. Then do "nvm use default" - symlink is created. Then add $HOME/.nvm/current/bin to your PATH in .profile

15
Avatar
Permanently deleted user

Igor, you totally nailed it!

Thanks

0
Avatar
Permanently deleted user

Igor Kalinovski, huge thanks! But it's may require relogin after described actions. Because in my case .nvm/current folder didn't exist.

1

I used Elena's method, and it worked really well. I prefered it to Igor's method, but if someone can tell me a reason why Igor's method is preferable, I will be very thankful.

0

I reached node/nvm/iTerm2 bliss in macOS Catalina by doing the following:

1. Moving everything I had in `.bashrc` to `.profile`

2. Changing `.bashrc` to just load `.profile` like so:

```

if [[ -f "${HOME}/.profile" ]]; then
    source "${HOME}/.profile"
fi

```

3. Following the post above from Igor, to create a "default" symlink

 

Everything now works great!

0

I'm using nvm and zsh. Coping the values

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

to `~./profile` worked. My `~./zshrc` and `~./bashrc` do not have the export and I'm using the self created desktop entry from Intellij. Session restart was required.

4

Add export NVM_SYMLINK_CURRENT=true to your .bashrc before NVM-stuff. Then do nvm use default - symlink is created. (Igor Kalinovskiy), then go to settings and choose node interpreter from the folder for nvm's current node version.

3

Please sign in to leave a comment.