cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] For higher version of node > 17.9.1 and npm cli > 8.11.0, npm pack is not packing "bundledDependencies"

Open mukundthakare opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

Recently I was upgrading Node.js version that I am using to my project, while doing so I found that using npm pack command to generate the .tgz tarball file is ignoring/not packing the bundledDependencies in the project.

With lower version of Node.js < 17.9.1 the npm pack command is working fine, meaning it is able to pack the bundledDependencies properly resulting in correct tgz file.

package.json of the folder that I want to pack looks like this:

{
    "name": "viewer-ng13",
    "version": "1.0",
    "peerDependencies": {
        "@angular/common": "^13.3.0",
        "@angular/core": "^13.3.0",
        "@angular/platform-browser": "~13.3.0",
        "@angular/forms": "~13.3.0"
    },
    "dependencies": {
        "tslib": "^2.3.0"
    },
    "bundledDependencies": [
        "core-3d",
        "loader",
        "viewer",
        "shared-ui"
    ]
}

The Folder structure is like below

release-ng
--viewer-ng13
----esm2020
----lib
----index.d.ts
----package.json
----nodemodules
------core-3d
------loader
------viewer
------shared-ui

So bundled dependencies are inside the node_modules/ folder.

Expected Behavior

I am expecting that like lower versions of Node.js I should be able to build .tgz file with higher/upgraded versions of Node.js.

Steps To Reproduce

  1. The bug ir reprodicible at any node version higher than 17.9.1
  2. npm pack release is the command that I am using to pack the folder.

Environment

Any node version higher than 17.9.1 the issue is reprodicuble.

mukundthakare avatar Feb 05 '24 17:02 mukundthakare

Presumably it's the npm version, not the node version, that matters here. What is the last npm version that works, and the first one that fails?

ljharb avatar Feb 05 '24 17:02 ljharb

@ljharb The last npm version on which it works on is 8.11.0

and the First npm version on which this fails is 9.5.1.

mukundthakare avatar Feb 06 '24 05:02 mukundthakare

@mukundthakare I believe npm does not bundle peer and dev dependencies, only prod dependencies will be bundled. Not sure if it's a typo or intentional but I see that bundledDependencies mentioned in package.json are missing from dependencies object.

milaninfy avatar Apr 04 '24 15:04 milaninfy

@milaninfy The doc does say it packs bundledDependencies. The followings links too. https://stackoverflow.com/questions/41941879/how-to-include-node-modules-also-while-npm-pack https://stackoverflow.com/questions/55786350/npm-pack-to-include-local-modules

so it is just a syntax I had used.

mukundthakare avatar Apr 05 '24 04:04 mukundthakare

bundleDependencies only bundles dependencies. It does not bundle packages that happen to be in node_modules (aka hoisted dependencies) as they are not considered dependencies. It does not bundle peerDependencies because those are supposed to be installed as peers (along side this package in node_modules).

None of the dependencies you are asking npm to bundle are actual dependencies of the package, so that is why this is not working.

wraithgar avatar Apr 14 '24 05:04 wraithgar

@wraithgar Same package.json works for lower version of npm. With your explanation it should not work for lower as well.

mukundthakare avatar Apr 15 '24 02:04 mukundthakare