NPM:在安装依赖于一个本地 tgz 包的模块时找不到包。

huangapple go评论86阅读模式
英文:

NPM: package not found when installing a module that dependes on a tgz local package

问题

我正在尝试安装一个npm包Module A,它依赖于一个本地的.tgz包,叫做Module B

例如,Module Apackage.json看起来像这样:

{
  "name": "module-a",
  "dependencies": {
    "module-b": "file:./forked-packages/module-b.tgz",
  }
}

当我尝试在不同的项目上安装Module A时,我收到以下错误:

npm警告:module-b@file:forked-packages/module-b.tgz的tarball数据(null)似乎已损坏。正在尝试再次下载。

然后它以ENOENT代码失败,说明找不到tgz路径。

奇怪的是,如果我运行npm pack module-a,然后检查module-b的存在,.tgz文件确实存在于正确的路径forked-packages/module-b.tgz

您有关于可能导致这个错误的任何想法吗?任何帮助将不胜感激。

提前感谢。

英文:

I am trying to install an npm package Module A that has a dependency on a local .tgz package, called Module B.

For instance, the package.json of Module A, looks something like this:

{
  "name": "module-a",
  "dependencies": {
   "module-b": "file:./forked-packages/module-b.tgz",
  }
}

When trying to install Module A on a different project, I am getting the following error:

> npm WARN tarball tarball data for module-b@file:forked-packages/module-b.tgz (null) seems to be corrupted. Trying again.

And then it fails with a ENOENT code stating that the tgz path was not found.

The weird thing is that if I run npm pack module-a, and then check for the existance of module-b, the .tgz does exist in the correct path forked-packages/module-b.tgz

Any idea of what could be causing this error? Any help would be appreciated.

Thanks in advance.

答案1

得分: 1

似乎发布到注册表的模块不能具有任何本地依赖项。来自文档的信息:

https://docs.npmjs.com/cli/v9/configuring-npm/package-json#local-paths

此功能对于本地离线开发和创建需要在其中进行npm安装但不希望访问外部服务器的测试非常有帮助,但在发布到公共注册表时不应使用。

注意:以本地路径链接的包在此情况下不会安装其自己的依赖项。您必须从本地路径本身运行npm install。

我正在尝试从私有注册表安装“模块A”,而这个模块将“模块B”作为本地tgz依赖项。

英文:

Seems that modules published to a registry must not have any local dependencies. From the docs:

https://docs.npmjs.com/cli/v9/configuring-npm/package-json#local-paths

> 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.
>
> note: Packages linked by local path will not have their own
> dependencies installed when npm install is ran in this case. You must
> run npm install from inside the local path itself.

I am trying to install Module A from a private registry, and this module has Module B as a local tgz dependency.

huangapple
  • 本文由 发表于 2023年6月22日 11:34:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76528460.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定