0

Although I'm running this setup inside a docker container, my project files are located in /app and /app/package.json exists

When I do cd /app && npm install --production (as root or non root user), all dependencies get installed in ~/.npm folder instead of showing up in /app/node_modules

I've also tried doing npm install --production --verbose --prefix /app but the folder node_modules still does not appear with the dependencies inside the app folder.

When I look at the error logs, I see messages like these for pretty much each dependency (eg: installing react).

npm verb tar unpack /root/.npm/base62/0.1.1/package.tgz
npm verb tar unpacking to /app/node_modules/react/node_modules/envify/node_modules/jstransform/node_modules/base62
npm verb gentlyRm don't care about contents; nuking /app/node_modules/react/node_modules/envify/node_modules/jstransform/node_modules/base62
npm verb gentlyRm don't care about contents; nuking /app/node_modules/react/node_modules/envify/node_modules/jstransform/node_modules/esprima-fb
npm verb tar unpack /root/.npm/source-map/0.1.31/package.tgz
npm verb tar unpacking to /app/node_modules/react/node_modules/envify/node_modules/jstransform/node_modules/source-map
npm verb gentlyRm don't care about contents; nuking /app/node_modules/react/node_modules/envify/node_modules/jstransform/node_modules/source-map
npm verb tar unpack /root/.npm/esprima-fb/13001.1001.0-dev-harmony-fb/package.tgz
npm verb tar unpacking to /app/node_modules/react/node_modules/envify/node_modules/jstransform/node_modules/esprima-fb
npm verb gentlyRm don't care about contents; nuking /app/node_modules/react/node_modules/envify/node_modules/jstransform/node_modules/esprima-fb

If I want to run as a root user, how can I get npm to always install all dependencies listed in package.json inside a node_modules folder in the app directory

Using npm@2.14.7, node@v4.2.3

Kartik
  • 9,463
  • 9
  • 48
  • 52
  • You may want to look at this : http://stackoverflow.com/questions/14469515/how-to-npm-install-to-a-specified-directory – Clément Berthou Dec 29 '15 at 09:34
  • Sadly, that approach did not work. If I run `npm install react` in the docker script, I see a node_modules folder but running `npm install` where the package.json has react listed does not create the node_modules folder – Kartik Dec 29 '15 at 09:39
  • I've got this same weird issue when running Node on Amazon Linux. Did you ever figure out an answer? – Doug Oct 26 '16 at 14:40

1 Answers1

0

Do npm install without --production. It should install in node_modules

Marko
  • 1
  • 3
  • I have tried that as well. Still doesn't. As a clarification, I am adding `--production` because there are devdependencies in package.json too. But even with a clean package.json with just 1 dependency, I still can't get it to install in a node_modules folder – Kartik Dec 29 '15 at 09:48
  • I think the reason why that is happening, is because you've been trying to install as root. You should checkout how to install packages without sudo. – Marko Dec 29 '15 at 09:52
  • This is a bit frustrating. I tried it as nonroot and the same thing happens. I just cannot get it to install anything in the same directory – Kartik Dec 29 '15 at 10:06
  • Try adding this to your .basrc file `PATH="$PATH:$HOME/.npm-packages/bin"` – Marko Dec 29 '15 at 10:19