Why is my "npm install" pulling in unnecessary libraries that I didn't even mention?

I've listed my dependencies in package.json as follows:

{
  "cookie-parser": "~1.0.1",
  "body-parser": "~1.0.0",
  "express": "~3.5.0",
  "socket.io":"1.0",
  "mongodb":"2.2.21",
  "request":"2.79.0", 
  "q":"1.4.1", 
  "bcryptjs":"2.4.0", 
  "jsonwebtoken":"7.2.1",
  "lodash":"4.17.4",
  "express-jwt": "5.1.0"
}

After running an NPM install, I encountered this unexpected output: https://i.sstatic.net/tVUVz.jpg

I'm puzzled by why I am receiving more dependencies than what I specified. The strange part is that on one PC I only get the requested dependencies, but on my laptop, all these additional ones are installed. It's quite confusing for me. I have the complete output available, but it appears messy if shared here.

Answer №1

Installing the selected packages comes with dependencies attached - therefore, be aware that by installing them you are also bringing along their dependencies.

Answer №2

To assist you, I have gone ahead and simulated a mock package.json with all of your required dependencies and proceeded to run an npm install.

It is worth noting that while the packages displayed were indeed those listed originally, executing an npm ls command will reveal the complete list of dependencies installed by each of those modules, as pointed out by Rivera in a response to your query.

If you wish to explore the entire dependency structure further, you can utilize the npm ls command. Detailed information is available at: https://docs.npmjs.com/cli/ls

Answer №3

To avoid any confusion regarding packages (which I've experienced myself), the best solution is to remove the node_modules folder and then run npm i again. Make sure that the list of dependencies in your package.json file (including dev-dependencies and regular ones) matches the output of the command: npm ls --depth="0".

It's important that on both your PC and laptop, the result of running npm ls --depth="0" matches the combined list of all dependencies listed in your package.json. If they don't match, it could imply that npm has taken matters into its own hands 😁.

Some readers on SO may have down-voted your question assuming you didn't grasp the concept of dependencies having their own dependencies, hence the creation of additional folders.

I sincerely hope this isn't the case and that you won't be deterred by any negativity encountered on SO.

Another potential explanation for your situation could be if you forgot to include --save when installing dependencies. This would result in the dependencies being saved in the node_modules folder without being added to your package.json, potentially leading to unnecessary installations.

By deleting the node_modules folder and reinstalling, only the dependencies specified in the package.json will be installed, ensuring a clean slate. This is why removing the node_modules folder first is recommended. Automated npm publishing tools like my favorite np often perform a similar wipe and reinstall process before publishing to avoid any lingering issues in the node_modules directory.

For more information on the importance of using --save, I recommend checking out this insightful answer.

In response to previous suggestions, Jonathan mentioned using npm ls, but I personally find it cumbersome for anything beyond simple libraries—too much scrolling. It's better to stick with npm ls --depth="0" to focus solely on the top level of your dependencies.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Images do not appear on Bootstrap Carousel as expected

I am facing an issue where the images are not displaying on my bootstrap carousel or when I try to display them individually using their class. I am utilizing bootstrap and express for my project. I have verified multiple times that the file path to the im ...

JavaScript library for creating animated car movements on a map using JPG images

Looking for a way to animate a car's movement on a map? I have a map image in jpg format (not svg) and a sequence of (x,y) points ready to go! If you could recommend a JavaScript library that can help me easily create an HTML page with this animation ...

Click on a link to navigate to a new page using the useNavigate hook in

I have successfully implemented navigation using the useNavigate hook, but I am wondering if there is a way to open the URL in a new tab instead of the current one. Is this achievable? Here's my code: import { useNavigate } from "react-router-do ...

Issue with Element Not Displaying During Page Load with Quick AJAX Request

I attempted to display a loading gif while making an ajax request that takes a long time to respond, and then hide the loading gif once the response is received. Here is the code snippet : $('.loading-gif').show(); $ajax({url:'',async ...

What are the steps to ensure a form does not trigger the action URL and instead only prints the data upon submission

Currently, I am working on creating a form that will submit without opening the action URL when a button is clicked. Additionally, after submission, I want to display a message and clear the form. Can anyone guide me on how to achieve this? <form id="c ...

Utilizing jQuery to efficiently chunk JSON data through AJAX calls

Is there a way to efficiently handle the retrieval of large amounts of JSON data through an ajax request? I am looking for a jQuery or JavaScript function that can assist with "chunking" the data. For example, I would like the ability to continuously rece ...

Encountering issues while attempting to initiate a React project

Recently, I started a fresh React project using Vite by running npm create vite@latest. However, when I proceeded with npm install and initiated the project with npm run dev, an unexpected error popped up: Error: @rollup/rollup-win32-x64-msvc module not fo ...

ToggleButton4 Framework is a user-friendly tool for creating interactive

I am currently working with Bootstrap 4 to design a toggle button; however, when I click the button, the checkbox does not update, despite the fact that the active class is being applied. Even when I use $('.btn-group-toggle').button('toggl ...

A simple guide to running Express Js and MongoDB from the command line and gracefully closing the terminal

Is there a way to run an Express project without the terminal being visible or easily closed? I need my server to stay running, but I don't want the user on the local PC to be able to see or close the terminal. Any suggestions on how to achieve this ...

What would be the optimal type for the second argument of the `simulate` method?

When using the simulate function, I am familiar with code like this: simulate("change", { target: { value: '7' } }); However, if my onChange function requires an object as a parameter, what should I pass in the second argument? interface myObj ...

Creating a task management system using HTML, CSS, and JavaScript that utilizes local

I have been extensively researching how to create a to-do list using JavaScript with local storage, but unfortunately, I have not been able to find exactly what I am looking for. Is there a way for me to set up a to-do list and input data before actually ...

AngularJS: Controller causing an unchecked error

I'm a beginner to AngularJS and I'm struggling to understand why I'm not getting a response when clicking the button. Any help would be greatly appreciated. I've reviewed other examples of controllers being used but I can't seem to ...

Setting up the NodeJS dropzone module

I am looking to integrate a dropzone component into my Node.js project. After running the command: npm install dropzone I found these files installed: node_modules/dropzone/dist/dropzone.js node_modules/dropzone/dist/dropzone.css However, I ...

Angular: The function t(...) does not support success - TypeError

My code is generating the error TypeError: t(...).success is not a function. I have tried searching for a solution but haven't been able to figure out why this error is happening in my specific case. Here is a snippet of my JS code. Can anyone point ...

Sending data from Node.JS to an HTML document

Currently, I am working on parsing an array fetched from an API using Node.js. My goal is to pass this array as a parameter to an HTML file in order to plot some points on a map based on the API data. Despite searching through various answers, none of them ...

jqGrid fails to display data retrieved from Java Servlet in JSON format

Seeking guidance in the right direction for populating jqGrid table with JSON data. I have reviewed several posts on this topic, such as: jqGrid - Table not being populated by data from json request jgGrid not displaying json data JSON and jqGrid. What ...

Getting row data in datatables after a button click: A step-by-step guide

Could somebody provide assistance with retrieving a single row of data on a click event? This table is dynamically populated after the AJAX call's Success function is executed <div class="table-responsive table-wrap tableFixHead container-flu ...

How to eliminate ampersands from a string using jQuery or JavaScript

I'm having trouble with a seemingly simple task that I can't seem to find any help for online. My CSS class names include ampersands in them (due to the system I'm using), and I need to remove these using jQuery. For example, I want to chan ...

Is it possible to display a combination of images and text data using JQUERY/AJAX, when the data is sent as objects or arrays?

I'm struggling to figure out how to handle an object or array sent from a server that contains binary picture and text data using JQUERY/AJAX Here is the server-side setup: const url= require('url'), express = require('express&ap ...

Error encountered when sending information to web service repeatedly

After populating an array with data, the information is logged into a database using a web service when the array reaches a specific record count. However, upon calling the web service, I encountered an error related to a parameter being passed: Error Ty ...