0

I'm trying to install packages into a project, by using npm install packagename. The install then goes on to install into /home/myusername/node_modules/packagename/node_modules/. Why is this happening? I'm guessing this has to do with the $NODE_PATH set in .bashrc.

Being new to Linux, I've copy pasted a lot. So, my .bashrc looks a bit messed up. This is all that's related to Node / NPM in my bashrc. Please help me so that the installations are the way they're supposed to.

# Allows for installing npm packages globally without sudo
NPM_PACKAGES="~/.npm-packages"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH  # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"

export NODE_PATH=~/.npm-packages/lib/node_modules:/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/anton/.npm-packages/lib/node_modules

### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export NODE_PATH=/home/anton/.npm-packages/lib/node_modules:/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/anton/.npm-packages/lib/node_modules:/home/anton/npm/lib/node_modules
export NODE_PATH=/home/anton/.npm-packages/lib/node_modules:/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/anton/.npm-packages/lib/node_modules:/home/anton/npm/lib/node_modules
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH

Thanks in advance, Anton

Apansson
  • 84
  • 2
  • 9

2 Answers2

1

I had a similar problem: the packages were installed not in the project folder I was in, but in the /Users/me directory.

My fix: initialize npm and create a package.json file in the project folder, by running npm init.

The post "npm install module in current directory" helped me get to this solution.

Community
  • 1
  • 1
theship
  • 75
  • 1
  • 13
0

I believe I understand your question. You are trying to have an install go into a certain directory.

If this is true, then you want to look into the command chroot or change root.

This will change the root directory to the current directory.

For example:

cd /your/project/directory

chroot ./chroot

Which will then change your root directory to the project's directory and install all files there. For more information look here: http://man7.org/linux/man-pages/man2/chroot.2.html

Chirality
  • 745
  • 8
  • 22
  • No, not really. I want npm to behave as it does default. When I install locally in a folder, it installs the packages into `/home/myusername/node_modules/packagename/node_modules/`. I don't want this - I want npm to create node_modules in the cwd, as expected. Thanks for answering. – Apansson Aug 15 '14 at 05:38
  • Alright. I had to take a stab with my linux point of view, but I found something online that might help. See (http://gruntjs.com/getting-started#the-gruntfil) (https://github.com/krampstudio/grunt-jsdoc/issues/93) (http://stackoverflow.com/questions/14032160/npm-install-to-current-directory) – Chirality Aug 15 '14 at 15:16
  • I believe that it's actually a Linux issue that stems from bashrc, somewhere up there. I'm quite familiar with npm and knows about -g vs local install. The problem I'm having is that when installing locally, the module/package ends up in a sub folder named as the package in `/home/myusername/node_modules/packagename/node_modules/`, no matter what my cwd is. – Apansson Aug 16 '14 at 12:41