我正在为NodeJS开发两个模块,第一个名为aligator,第二个名为aligator-methods.第二个取决于第一个.我正在同时开发这两个模块,我想全局链接aligator,这样我就可以像在npm注册表上一样使用它,我只是在全局范围内安装了它.为了完成这个NPM文档,我需要使用npm link,但它不起作用.

模块aligator的文件package.json:

{
  "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创建了一个全局引用,现在我可以在计算机中的任何地方使用这个模块.

然后我转到另一个模块,try 安装依赖项,但它给了我以下输出:

$ 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

但它也不起作用.

Any thoughts on what it is that could be happening?我在某个地方读到,它可能与我安装的nodenpm有关,因为它是brew 的,所以有时我需要使用sudo,这似乎不太可能,但我try 了他们提出的方法,但也没有成功.

推荐答案

问题是package.jsonmain属性指向一个不存在的文件.似乎这个问题可能是由多种原因造成的,所以一定要看看其他答案.

Node.js相关问答推荐

如何从puppeteer的page. evaluate()中获取流数据?(node.js)

nest js控制器方法调用两次

如何在mongodb集合中设置数据限制?

MongoDB如果文档S的字段小于另一个字段,则将该字段加一

使用NodeJS的DynamoDB中的BatchGetItem出现MultipleValidationError

仅在一次查询中 MongoDB 上最近的一对位置

Next.js 路由不起作用 - 页面未正确加载

如果我在父文件夹中运行,子进程生成不起作用

如何使用mongoose引用不在项目中的模型

如何修复我的 NodeJS SSE 写入函数以在后续调用中更新 HTML?

无法通过 NextJS 访问 HTTP 帖子中的正文

Typescript :泛型类又扩展了另一个泛型类

如何在mongoose 聚合中执行全文搜索

在 linux mint 上部署 node 应用程序的最简单方法是什么?

如何让 vscode 假设一个 node.js 上下文,以便它不假设 `fetch` 存在?

用户通过 oauth2 twitter 授权或通过Passport discord后如何重定向到 React/Vue 路由?

file.slim.js 中的苗条是什么

代理(如提琴手)可以与 Node.js 的 ClientRequest 一起使用吗

NodeJS 中的 HTTPS 请求

nodemon + express,监听端口=?