NPM:找不到“npm link”模块

我正在为NodeJS开发两个模块,第一个名为aligator ,第二个是aligator-methods 。 第二个依赖于第一个工作。 我正在开发这两个模块在同一时间,我想要全球链接aligator所以我可以使用它就像在npmregistry,我只是安装在全球范围内。 要做到这一点NPM文件说,我需要使用npm link但它不工作。

文件package.json模块aligator

 { "name": "aligator", "version": "0.0.1", "description": "", "main": "index.js", "private": true, "directories": { "doc": "docs", "example": "examples", "test": "spec" }, "scripts": { "test": "gulp jasmine" }, "author": "Roc Alayo Arnabat", "license": "MIT", "devDependencies": { "gulp": "^3.6.2", "gulp-jasmine": "^0.2.0", "gulp-jshint": "^1.6.1", "gulp-rename": "^1.2.0", "jasmine-node": "^1.14.3" }, "dependencies": { "bluebird": "^1.2.4", "lodash": "^2.4.1", "mathjs": "^0.22.0" } } 

文件package.json模块aligator-methods

 { "name": "aligator-methods", "version": "0.0.1", "description": "", "main": "index.js", "private": true, "directories": { "doc": "docs", "example": "examples", "test": "jasmine" }, "scripts": { "test": "gulp jasmine" }, "author": "", "license": "MIT", "devDependencies": { "gulp": "^3.6.2", "gulp-jasmine": "^0.2.0", "gulp-jshint": "^1.6.1", "gulp-rename": "^1.2.0", "jasmine-node": "^1.14.3" }, "dependencies": { "lodash": "^2.4.1", "mathjs": "^0.22.0", "aligator": "^0.0.1" } } 

首先我把模块全局链接起来:

 $ cd ~/aligator $ npm link /usr/local/lib/node_modules/aligator -> /Users/roc/aligator 

这个如果我没有弄错,已经创build了我的模块aligator的全球参考,现在我可以在任何地方使用这个模块在电脑中。

然后我去了另一个模块,并试图安装依赖项,但它给了我这个输出:

 $ cd ~/aligator-methods $ npm install npm ERR! 404 404 Not Found: aligator npm ERR! 404 npm ERR! 404 'aligator' is not in the npm registry. npm ERR! 404 You should bug the author to publish it npm ERR! 404 It was specified as a dependency of 'aligator-methods' npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, or http url, or git url. npm ERR! System Darwin 13.2.0 npm ERR! command "node" "/usr/local/bin/npm" "install" npm ERR! cwd /Users/roc/aligator-methods npm ERR! node -v v0.10.28 npm ERR! npm -v 1.4.16 npm ERR! code E404 npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /Users/roc/aligator-methods/npm-debug.log npm ERR! not ok code 0 

我甚至试图直接链接:

 $ cd ~/aligator-methods $ npm link aligator /Users/roc/aligator-methods/node_modules/aligator -> /usr/local/lib/node_modules/aligator -> /Users/roc/aligator 

但它也没有工作。

任何想法可能会发生什么? 我读了一些地方,可能它与我的节点npm的安装有关,因为它是由Homebrew制作的,所以有时候我需要使用sudo ,似乎不太可能,但是我尝试了他们所提出的,它也不起作用。

编辑:解决我的具体问题

在我的情况下,问题是package.jsonmain属性指向一个不存在的文件。

我遇到了这个问题,因为NVM,我运行一个版本的依赖节点和另一个依赖。

当您首次从aligator目录运行npm link ,您将创build从全局node_modules目录到aligator的链接。 然后,当您从aligator-methods目录运行npm link aligator ,将aligator从本地安装的node_modules链接到原始源(如上面的示例中所示)。 一旦完成,就不需要再安装了,因为它已经被“安装”了。 在运行npm link aligator命令后,你看到了什么错误?

如果您只想从本地目录安装依赖项,则可以尝试使用npm install 。 例如:

$ cd〜/ aligator-methods
$ npm install ../aligator

对我来说,当我本地包的版本号从0.1.0降低到0.0.1时,就发生了这种情况。 而在我链接到这个包的项目中,我还在使用更高的版本号。 更新package.json依赖关系修复了它。

修复这个问题的版本; 在npm v5.3.0中,我从回购中删除了node_modules ,我正在链接到另一个项目中。

我发现,在npm v3之后,他们尝试将所有node_modules依赖关系放入一个node_modules目录(一个在您的项目中),以尽可能平坦化结构( http://codetunnel.io/npm-5-changes-to-npm – 链接/ )。

对我来说,解决办法是在我的要求声明中有一个错字。

 require('my_liberry') 

一旦我input正确的东西,它的工作。