cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npm install <localFolder> removes bundledDependency

Open vladiulianbogdan opened this issue 1 year ago • 3 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

I have a module defined in a folder. It has it own package.json and a node_modules folder that contains other-lib dependency. The other-lib dependency is not pushed in any registry.

{
  "name": "my-lib",
  "version": "1.0.0",
  "bundleDependencies": [
    "other-lib"
  ],
  "description": "",
  "main": "./lib/index.js",
  "dependencies": {
    "other-lib": "1.0.0"
  }
}

If I install my-lib from the folder with npm install ./my-lib-folder in an existing project, the node_module/other-lib folder is removed.

Expected Behavior

The node_modules folder from the module my-lib should not be removed. If i run npm pack in the my-lib folder, the node_modules/other-lib folder is kept. Also, if I push my-lib to a registry and I install it via npm install the node_modules/other-lib folder is still present.

Steps To Reproduce

See comment below.

Environment

  • npm: 10.5
  • Node.js: v18.18.1
  • OS Name: OS Ventura

vladiulianbogdan avatar Mar 11 '24 21:03 vladiulianbogdan

@vladiulianbogdan I tried to reproduce based on given issue description, but i was unable reproduce. Please include steps to reproduce.

milaninfy avatar Mar 12 '24 14:03 milaninfy

I've attached the following zip:

client-ts.zip

In the ./sdk folder you can see a dependency that has a bundled dependency "genezio-remote".

Steps to reproduce:

  1. Run npm install ./sdk. This will produce the first weird behaviour since it creates a symlink to my folder. This is against what I understand from the npm documentation:

npm install <folder>:

If <folder> sits inside the root of your project, its dependencies will be installed and may be hoisted to the top-level node_modules as they would for other types of dependencies. If <folder> sits outside the root of your project, npm will not install the package dependencies in the directory <folder>, but it will create a symlink to <folder>.

(source)

  1. If you run one more npm install you will see the following output.
iulian-bogdanvlad@Iulian-Bogdans-MacBook-Pro client-ts 2 % npm install

removed 1 package, and audited 263 packages in 3s

Now the bundled dependency has disappeared (you can check with ls node_modules/qweqweq/node_modules).

vladiulianbogdan avatar Mar 27 '24 12:03 vladiulianbogdan

@vladiulianbogdan If you need to change symlink behaviour, you can try enable this flag https://docs.npmjs.com/cli/v10/using-npm/config#install-links.

milaninfy avatar Apr 10 '24 19:04 milaninfy