`npm install <folder>` doesn't behave the same as `cd <folder> && npm install`

I have a source tree like this:

myapp
├── nodestuff1
|    └── package.json
└── nodestuff2
     └── package.json

nodestuff1/package.json includes this:

"prepublish": "npm install ../nodestuff2"

nodestuff2/package.json includes this:

"devDependencies": {"uglify-js": "2.3.x"}

My workflow is supposed to be cd myapp/nodestuff1 && npm install, which should first install nodestuff2 followed by nodestuff1. However...

  • running npm install in myapp/nodestuff2 installs devDependencies, whereas
  • running npm install ../nodestuff2 does not install devDependencies.

For now I changed the prepublish script to cd to nodestuff2 and run npm install there, then cd back to nodestuff1 and run npm install ../nodestuff2 so that it gets copied to nodestuff1/node_modules.

Is this a bug? Is there a better solution?

First, understand that the semantics of "cd someproject && npm install" means "install someproject's dependencies and devDependencies so I can run it and/or develop it" as opposed to "npm install ../someproject" which means "install someproject in the current directory so I can use it from my project or from the repl", which does not install devDependencies. These make sense to me personally but that may or may not be intuitive to you, but in either case, that's how npm works.

Now, for your packages, if I understand what you are trying to do is pre-bundle nodestuff2 within nodestuff1 when you publish it to npm. Don't do that. Instead, just list nodestuff2 as a dependencies of nodestuff1 in nodestuff1/package.json. Are you trying to do something unusual here? If you provide the larger context of what you are trying to accomplish, it will be easier for people to post answers. My impression is you are working against the grain of npm but you haven't provided enough context for me to really assess what you are doing.