Simply, trying to
npm install -g something
something and in node
let c = require('something')
says that it
Cannot find module 'something'
However, I don't think I've messed around with any node/npm paths.
I can fix this by running
export NODE_PATH=$(npm root -g)
(which is /usr/local/lib/node_modules
)
But I am wondering why I have to do this in the first place. What is the default NODE_PATH
that node
is looking at, that I am changing to npm root -g
?
I'm on macOS Catalina running the latest versions of npm
and node
To summarize, my question is just about why this behavior is happening. I already have a described the workaround for this, but you would think that node
would use npm root -g
as its default global req path by default.