I have a downloaded module repo, I want to install it locally, not globally in another directory?
What is an easy way to do this?
I have a downloaded module repo, I want to install it locally, not globally in another directory?
What is an easy way to do this?
Neither of these approaches (
npm link
orpackage.json
file dependency) work if the local module has peer dependencies that you only want to install in your project's scope.For example:
In this scenario, npm sets up
myproject
'snode_modules/
like this:When node loads
mymodule
and it doesrequire('foo')
, node resolves themymodule
symlink, and then only looks in/local/mymodule/node_modules/
(and its ancestors) forfoo
, which it doen't find. Instead, we want node to look in/local/myproject/node_modules/
, since that's where were running our project from, and wherefoo
is installed.So, we either need a way to tell node to not resolve this symlink when looking for
foo
, or we need a way to tell npm to install a copy ofmymodule
when the file dependency syntax is used inpackage.json
. I haven't found a way to do either, unfortunately :(you just provide one
<folder>
argument tonpm install
, argument should to the local folder instead of the package name:From the npm-link documentation:
In the local module directory:
In the directory of the project to use the module:
Or in one go using relative paths:
This is equivalent to using two commands above under the hood.
Since asked and answered by the same person, I'll add a npm link as an alternative.
from docs:
[Edit] As of NPM 2.0, you can declare local dependencies in package.json