Npm bundled dependencies not working as expected

Viewed 559

I am using node 14 with npm 6 where the bundledDependencies should be supported.

I am trying to have this setup:

  • package-C is the bundled dependency of package-B
  • package-B is the dependency of package-A

then I expect I can use APIs exposed by package-C when developing package-A without having package-C as the dependency or devDependency in package-A's package.json.

However, this is not working as require.resolve("package-C") throws "Cannot find module" error under package-A.

Then I check the package-lock.json of package-A and I don't see any dependencies listed under package-B entry (I am trying to check if package-B -> package-C has bundled set as true or not).

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

During the npm pack of package-B, however, I do see the following output indicating package-C being bundled:

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

Can someone help?

1 Answers

I did more experiments and below are my findings:

  • bundling of a dependency (package-C) in a package (package-B) does not make the bundled dependency (package-C) available for the dependant package (package-A)
  • bundled package (package-C) is only available to which package (package-B) it is bundled
  • the purpose of bundling is to make a locally modified dependency (package-C, which is not generally available from NPM registry via an npm install) available to the bundling package (package-B) when it is used by the dependant package (package-A)

My attempt of bring in transitive dependencies via a dependency using bundledDependencies is wrong from the very beginning as it is not supported at all.

Related