Neither of these approaches (npm link
or package.json
file dependency) work if the local module has peer dependencies that you only want to install in your project's scope.
For example:
/local/mymodule/package.json:
"name": "mymodule",
"peerDependencies":
{
"foo": "^2.5"
}
/dev/myproject/package.json:
"dependencies":
{
"mymodule": "file:/local/mymodule",
"foo": "^2.5"
}
In this scenario, npm sets up myproject
's node_modules/
like this:
/dev/myproject/node_modules/
foo/
mymodule -> /local/mymodule
When node loads mymodule
and it does require('foo')
, node resolves the mymodule
symlink, and then only looks in /local/mymodule/node_modules/
(and its ancestors) for foo
, 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 where foo
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 of mymodule
when the file dependency syntax is used in package.json
. I haven't found a way to do either, unfortunately :(