在何处以及如何将 package.json 置于 tgz 依赖项中

Where and how to put the package.json in a tgz dependency

我正在尝试构建一个将存储到 .tgz 中的节点库

问题是当我在另一个 npm 项目中安装这个库时,出现错误:

Non-registry package missing package.json: easy-rules-core@file:/Users/sbuisson/.m2/repository/org/jeasy/easy-rules-core-js/3.2.4/easy-rules-core-js-3.2.4.tgz.

我的tgz的文件结构:

easy-rules-core-js-3.2.4.tgz
  -> package
     ->package.json
     ->index.js
     ->node_modules

我也试过没有成功:

easy-rules-core-js-3.2.4.tgz
     ->package.json
     ->index.js
     ->node_modules

我应该把 package.json 放在哪里?

额外问题:我需要将 node_modules 文件夹放入 tgz 中吗?

在您的项目文件夹中尝试 npm pack 命令。它应该创建一个结构正确的 .tgz 文件。它应该是这样的(没有 node_modules 文件夹):

easy-rules-core-js-3.2.4.tgz
  -> package
     ->package.json
     ->index.js

然后复制父模块根文件夹中的 .tgz 文件和运行: npm install ./easy-rules-core-js-3.2.4.tgz.

这将在将以下行添加到您的 package.json 时处理安装: "easy-rules-core-js": "file:easy-rules-core-js-3.2.4.tgz"。或者,您可以手动将依赖项添加到 package.json.

更多信息: