Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set $NODE_PATH when using nvm?

Tags:

node.js

nvm

I have installed node in my ubuntu system using nvm. It has been working smoothly until now, but one of my project neds $NODE_PATH set and nvm isn't setting it.

I would manually set it but I use multiple version of node. What is the best way to solve this.

I get following results from terminal commands

node -v
v8.9.1

npm -v
5.5.1

which node
/home/username/.nvm/versions/node/v8.9.1/bin/node

echo $NODE_PATH
[nothing]

nvm --version
0.33.6

nvm ls
->       v8.9.1
         v9.0.0
default -> v8.9.1
six -> lts/boron (-> N/A)
node -> stable (-> v9.0.0) (default)
stable -> 9.0 (-> v9.0.0) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.9.1)
lts/argon -> v4.8.6 (-> N/A)
lts/boron -> v6.12.0 (-> N/A)
lts/carbon -> v8.9.1

I have read other similar questions and answers there didn't help. I have already tried commands like

nvm use 8.9.1

nvm alias default 8.9.1

These commands do not solve it.

like image 673
Ragas Avatar asked Sep 03 '26 14:09

Ragas


1 Answers

(nvm maintainer here)

nvm intentionally does not set NODE_PATH because it's an antipattern to use it - it allows you to require things that aren't locally installed.

You can manually set it yourself, after running nvm use, but it should not be needed at all. nvm doesn't provide any hooks to set it automatically (by design).

Thus, the best way to solve it is to refactor your project so that it no longer relies on this deprecated feature, that node itself isn't going to support with its native ES Modules implementation whenever that lands.

like image 54
LJHarb Avatar answered Sep 05 '26 06:09

LJHarb