我想这样做,所以npm install也会安装这个包。Json的../somelocallib或者更重要的是它的依赖项。

"dependencies": {
    "express": "*",
    "../somelocallib": "*"
}

当前回答

这对我来说很有效:首先,确保npm目录有正确的用户

sudo chown -R myuser ~/.npm
sudo chown -R myuser /usr/local/lib/node_modules

那你就在你的包裹里。Json链接目录

"scripts": {
 "preinstall": "npm ln mylib ../../path/to/mylib"
}, 
"dependencies": {
  "mylib" : "*"
}

其他回答

实际上,从npm 2.0开始,现在已经支持本地路径了。

好奇……至少在Windows上(我的npm是3.something),我需要做:

"dependencies": {
 "body-parser": "^1.17.1",
 "module1": "../module1",
 "module2": "../module2",

当我做npm安装../module1——保存它会导致绝对路径,而不是文档中的相对路径。

我又瞎折腾了一下,然后决定…/xxx就足够了。

具体地说,我有本地节点模块检出说d:\build\module1, d:\build\module2和我的节点项目(应用程序)在d:\build\nodeApp。

为了“安装”,我:

d:\build\module1> rmdir "./node_modules" /q /s && npm install
d:\build\module2> rmdir "./node_modules" /q /s && npm install
d:\build\nodeApp> rmdir "./node_modules" /q /s && npm install

module1的包。Json有一个依赖项"module2": "../module2";Module2没有本地依赖;nodeApp有依赖"module1": ".."../ module1"和"module2": "../module2"。

不确定这是否只适用于我,因为所有3个文件夹(module1, module2和nodeApp)都位于同一个级别.......

这对我来说很有效:首先,确保npm目录有正确的用户

sudo chown -R myuser ~/.npm
sudo chown -R myuser /usr/local/lib/node_modules

那你就在你的包裹里。Json链接目录

"scripts": {
 "preinstall": "npm ln mylib ../../path/to/mylib"
}, 
"dependencies": {
  "mylib" : "*"
}

这是如何添加本地依赖项的:

npm安装文件:src/assets/js/FILE_NAME

把它添加到包中。json来自NPM:

保存文件:src/assets/js/FILE_NAME

直接添加到包。Json是这样的:

....
  "angular2-autosize": "1.0.1",
  "angular2-text-mask": "8.0.2", 
  "animate.css": "3.5.2",
  "LIBRARY_NAME": "file:src/assets/js/FILE_NAME"
....

现在可以在包中指定本地Node模块安装路径。直接json。从文档中可以看出:

Local Paths As of version 2.0.0 you can provide a path to a local directory that contains a package. Local paths can be saved using npm install -S or npm install --save, using any of these forms: ../foo/bar ~/foo/bar ./foo/bar /foo/bar in which case they will be normalized to a relative path and added to your package.json. For example: { "name": "baz", "dependencies": { "bar": "file:../foo/bar" } } This feature is helpful for local offline development and creating tests that require npm installing where you don't want to hit an external server, but should not be used when publishing packages to the public registry.