Npm绑定的依赖项未按预期工作



我正在使用节点14和npm 6,其中应该支持bundledDependencies

我正在尝试这个设置:

  • package-C是package-B的绑定依赖项
  • 包B是包A的依赖项

那么我希望在开发package-A时可以使用package-C公开的API,而不需要将package-C作为package-A的package.json中的依赖项或devDependency。

然而,这不起作用,因为require.resolve("package-C")抛出"0";找不到模块";软件包A下出现错误。

然后,我检查了包A的package-lock.json,没有看到包B条目下列出的任何依赖项(我正在尝试检查包B->包C是否将bundled设置为true(。

{
"name": "package-A",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"package-B": {
"version": "1.0.0"
// I am wishing to see something like the following but there is not:
// "dependencies": {
//   "package-C": {
//     "version": "1.0.0",
//     "bundled": true
//   }
// }
}
}
}

然而,在包B的npm pack期间,我确实看到以下输出指示包C被捆绑:

npm notice
npm notice 📦  package-B
npm notice === Tarball Contents ===
npm notice redacted
npm notice === Bundled Dependencies ===
npm notice package-C
npm notice === Tarball Details ===
npm notice name:          package-B
npm notice version:       1.0.0
npm notice package size:  17.7 MB
npm notice unpacked size: 127.5 MB
npm notice shasum:        redacted
npm notice integrity:     redacted
npm notice bundled deps:  1
npm notice bundled files: 4142
npm notice own files:     18
npm notice total files:   4160
npm notice

有人能帮忙吗?

我做了更多的实验,下面是我的发现:

  • 将依赖项(package-C(绑定到包(package-B(中不会使绑定的依赖项(package-C(可用于从属包(package-a(
  • 捆绑包(C包(仅适用于捆绑的包(B包(
  • 绑定的目的是使本地修改的依赖项(包C,通常不能通过npm install从NPM注册表获得(在被依赖包(包a(使用时可用于绑定包(包B(

我使用bundledDependencies通过依赖项引入可传递依赖项的尝试从一开始就错了,因为它根本不受支持。

最新更新