NPM:找不到“npm link”模块后

新手上路,请多包涵

我正在为 NodeJS 开发两个模块,第一个名为 aligator 和第二个 aligator-methods 。第二个取决于第一个工作。我正在同时开发这两个模块,我想全局链接 aligator 所以我可以像在 npm 注册表上一样使用它,我只是在全球范围内安装它。要做到这一点,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"
  },
  "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"
  }
}

模块 aligator-methods 的文件 package.json

 {
 "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

如果我没记错的话,这已经为我的模块创建了一个全局引用 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

但它也没有奏效。

关于可能发生的事情有什么想法吗? 我在某处读到可能与我安装 nodenpm 有关,因为它是由 Homebrew 制作的,所以有时我需要使用 sudo ,这似乎不太可能,但我尝试了他们的建议,但它没有也不行。

原文由 Roc 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 920
2 个回答

问题是 main 属性 package.json 指向一个不存在的文件。似乎该问题可能由于多种原因而发生,因此请务必查看其他答案。

原文由 Roc 发布,翻译遵循 CC BY-SA 4.0 许可协议

由于 NVM,我遇到了这个问题,我正在为依赖项运行一个版本的节点,为依赖项运行另一个版本。

原文由 linuxdan 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏