Red Hat Bugzilla – Bug 1031725
npm modules installed on a nodejs application are not displayed
Last modified: 2015-05-14 20:34:53 EDT
+++ This bug was initially created as a clone of Bug #1031718 +++
Description of problem: npm modules installed on a nodejs application are not shown at 'npm ls' or 'npm ls --json'
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Create a nodejs application
2. add a dependency/dependencies in "package.json". For eg :
3. git add>commit>push, the output shows npm modules are installed.
4. ssh to the application and run 'npm ls --json' or 'npm ls' it does not return the installed npm modules.
ssh to the application and run 'npm ls --json' or 'npm ls' it does not return the installed npm modules.
It should list the installed npm modules
I think the root cause is that node packages are installed under $OPENSHIFT_REPO_DIR/node_modules/ rather than $OPENSHIFT_DEPENDENCIES_DIR/node_modules , but $OPENSHIFT_HOMEDIR/.node_modules (incorrectly?) links to $OPENSHIFT_DEPENDENCIES_DIR/node_modules. Hence, the installed packages will not be displayed when sourcing under $OPENSHIFT_HOMEDIR.
Here is the debugging to support my stand:
1. install the following dependencies:
during the installation, we can see from the console that the packages are installed under $OPENSHIFT_REPO_DIR/node_modules/ e.g.,
remote: npm info build /var/lib/openshift/528c1d63ebf58c2441000007/app-root/runtime/repo/node_modules/yo
2. when checking the installed packages under $OPENSHIFT_DEPENDENCIES_DIR/node_modules, we can see that the packages are present under this dir, but $OPENSHIFT_HOMEDIR/.node_modules is linked to it.
lrwxrwxrwx. 1 528c2105ebf58c244100002a 528c2105ebf58c244100002a 78 Nov 19 21:40 .npm -> /var/lib/openshift/528c2105ebf58c244100002a/app-root/runtime/dependencies/.npm
3. sourcing node packages under $OPENSHIFT_HOMEDIR will return an empty list as this bug described.
4. sourcing node packages under $OPENSHIFT_REPO_DIR/ will return the installed packages, for example,
[njs-dev4051tst.dev.rhcloud.com repo]\> npm ls | grep yo
I am not sure if the different behaviours between $OPENSHIFT_DEPENDENCIES_DIR/node_modules and $OPENSHIFT_REPO_DIR/node_modules are by design, and I would appreciate a lot if you could help to make it clear.
Sorry, in step 2, it should be "we can see that the packages are NOT present under this dir, but $OPENSHIFT_HOMEDIR/.node_modules is linked to it"
As best I can tell, this has always been the behavior. I tested on a devenv based on stage_528 (which was before we had $OPENSHIFT_DEPENDENCIES_DIR), and running "npm ls" from the home directory of the gear returns 0 modules, even if you have some installed. If you cd into app-root/runtime/repo and run "npm ls" it will display whatever modules you have installed.
We can create a Trello card if you'd like for trying to install application npm modules into $OPENSHIFT_DEPENDENCIES_DIR/nodejs/node_modules instead of app-root/runtime/repo/node_modules, but I'm not sure of the feasibility and/or implications of doing that.
I do not think this is ever going to work as the reporter desires since npm will only report modules installed under the working directory, and rhc ssh will never take you to either the app-root or the dependencies directory, which are the two places the modules can be installed.
*** Bug 1031718 has been marked as a duplicate of this bug. ***