Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Allow subdirectories within git repos in npm install #2974

SLaks opened this Issue · 22 comments

I would like to be able to run npm install for a package.json file in a subdirectory of a git repo.

This would be useful for projects that use releases systems (such as nzakas/parserlib), and for git repos that contain multiple npm packages .

Can this be added?

@SLaks SLaks referenced this issue in CSSLint/parser-lib

Release only timestamp #45


cd subdirectory && npm install :D


Same problem I have with - the actual module (package.json) is in a src/ subdirectory, but I don't find a way to reference that subdir from the package.json of a module that depends on it.
Is that possible ? (can't script a cd && npm install in package.json, can I?)


you could try something like {"scripts":{"install":"cd src && npm install"}} in your package.json.

but that is just not how its meant to be done

but I don't find a way to reference that subdir from the package.json of a module that depends on it

when your module depends on another module that other module will be installed in node_modules/<module-name> and in that directory there will be its package.json. thats not only how npm does it - thats how the node-modules work, see

so i am pretty sure, the way how it works now will not change (its set in stone)


@SLaks There's no plans to do this. If npm installs a git repo, it assumes that the git repo is the package. I don't really know how we could specify a sub-path easily, since all parts of the git url are already used for other things. For example, git:// Where would you put the subpath in there, such that it can be deterministically differentiated from the path to the repo in all cases? I don't see any way to do it without resorting to some awful hacks.

How would you express this?


+1 for this use case. For me, it's about including tests from other components (Java components). We use mocha to test these things, and service A wants to import service B's tests but we can't use npm because it doesn't have the concept of branches. Since the tests will be against some branch of service A, AND because the tests are part of the service rather than their own repo, we would benefit from subtree installs in GIT. Maybe another argument like --nodedir?


This would be great. I'm using highlight.js which stores its source, including package.json, in src/.


This would indeed be great. As it is I will have to make a whole bunch of dummy projects. I hope that I can simply have each main project as a git submodule and put a link called package.json to the real package.json. That might break though...


any news on that? or is there a workaround for that case?




+1 Unfortunately not all npm git repos can store their contained npm module in their root's!



@gaboom: That's actually a breaking change, in the (admittedly unlikely) case of // appearing in a git URL path.


brackets are only legal as IPv6 literal hostnames, needs to be escaped otherwise.


I could definitely use this feature too.

We have a Git repository with several of our product's subsystems, and I want to be able to use npm to install individual micro-services as packages from their subdirectories (services/{package-name}/package.json).


Another +1, I agree URL syntax is ugly but apache/thrift is a good example of a nodejs project embedded in a bigger repo and trying to work with a non-tagged release is made very hard without this feature.


Another +1.


Another +1. Need to import other module that's not in the root and don't want to create a specific project for that module.


Another +1


strongly +1



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.