Updating dependencies of dependencies in npm: A step-by-step guide

I'm puzzled by the fact that I can't seem to find a solution to this seemingly easy question. It's surprising that even running npm update doesn't resolve the issue.

While I can't post my entire dependency tree here, I'll do my best to explain the problem:

The version of minimist currently being used is outdated (1.2.0) and poses a security risk in this state. Despite packages requiring minimist specifying ^1.2.0 - which should be compatible with 1.2.2.

The standard fix involves adding it to either devDependencies or dependencies in package.json with ^1.2.2. However, I prefer not to modify package.json. I believe that npm update should also address indirect dependencies.

Is there something obvious I am overlooking?

You can view my package-lock.json file here: https://github.com/tflori/riki-community/blob/master/package-lock.json

And here is the output of npm ls minimist:

 *output as provided from original text*

Answer №1

To resolve this issue, it is recommended to update npm to version greater than or equal to 7.0. For more information, refer to xeos's answer for detailed instructions. If updating npm is not feasible, there are two alternative solutions:


The underlying problem lies in the depth of the dependencies. According to the documentation:

Starting from [email protected], npm update only examines top-level packages. In previous versions, npm would also recursively analyze all dependencies. To revert to the old behavior, use npm --depth 9999 update.

Hence, specifying the desired depth is essential for the update process. In my case, a depth of 9999 was too time-consuming, so I opted for a --depth 5 parameter instead.

npm update --depth 5

If the update still fails to address the dependency issue, manual modification of the package-lock.json file is necessary.

Open the package-lock.json file and eliminate all instances of "minimist": { from the file.

For instance:

Replace this:

      "dependencies": {
        "minimist": {
          "version": "1.2.0",
          "bundled": true,
          "dev": true,
          "optional": true
        }
      }

with:

      "dependencies": {
      }

Subsequently, run npm install again.

Answer №2

Starting with npm version v7.0.0, when you run the command npm update, it will now update all packages, not just the ones listed in the root package.json file. The --depth option has been removed from the npm update command and its behavior has been changed.

Keep in mind that there might be cases where a package specifies an outdated version as a dependency, which can prevent npm update from installing the latest version. In such situations, your only choice might be to force a resolution to a more recent version.

Answer №3

For those looking to update all dependencies recursively, I have found a highly efficient and reliable solution:

To begin, ensure that you commit any changes in case issues arise with git commit package*.json. Next, update your direct dependencies as needed using npm outdated and npm update xyz

Now, proceed to update all package versions by creating a new clean build of the package-lock.json file:

# delete current node_modules/ and package-lock.json
rm -rf package-lock.json node_modules/

# regenerate package-lock.json with the most up-to-date 
# semantically-compatible package versions & install node_modules/
npm install

# run tests to ensure everything is functioning properly
npm test

In the event of any issues, revert back to the previous state:

rm -rf package-lock.json node_modules/
git checkout package*.json
npm install

On a side note, this approach has proven successful for me, yet I am continually expanding my knowledge of NPM and package-lock functionality. I am eager to receive insights from other esteemed NPM professionals regarding this strategy.

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

Error 504 occurs on Express.js due to a timeout issue while a timer is active

Encountering a "504 Gateway Timeout" error on my Express.js application when a JavaScript timer is set to run every 20 seconds. Here is the code for my Express.js listener and the timer: const express = require('express') const app = express() ...

Creating flexible Vue routes using a single router component and a navigational menu

I am working on a Vue project and I want to implement nested routes in my router.js. My goal is to have just one menu for all the nested routes and only one <router-view></router-view> in a master component. This is what I envision (in pseudoc ...

Changing an object received as a prop in Vue.js

Is it acceptable to mutate values in a prop when passing an Object reference? In the process of developing a web application that involves passing numerous values to a component, I am exploring the most efficient method of handling value passing between c ...

Using a separate iteration of Python while conducting an NPM installation

I have admin privileges on a VPS running CentOS 5.9 with Python 2.4.3 installed by default. I decided to upgrade to Python 2.7.3 using the commands below (I opted for make altinstall instead of make install): wget http://www.python.org/ftp/python/2.7.3/Py ...

I'm struggling to retrieve $wpdb data after using a PHP function to load my posts with AJAX

Hey there! I'm trying to create a cool feature where users can view post archives grouped by year. When they click on a specific year, all the posts from that year should be displayed. I've set up an AJAX call to my functions.php file, which con ...

How to creatively position custom arrows in a React JS Nuka Carousel

Seeking assistance on properly positioning custom arrows within the Nuka Carousel component. After combining the decorators, I found that both of my arrows are appearing side by side. How can I address this issue? My goal is to have one arrow positioned in ...

Ensure that JavaScript functions are executed sequentially without overlapping

Important : Absolutely no jQuery allowed I have developed four distinct functions and I am looking to execute them sequentially, one after the other in JavaScript without using jQuery. I have scoured the internet for a solution but unfortunately have not ...

Set the property state to false based on the value of another property in Mongoose Express NodeJS

I am trying to update the status property of a sale based on the outstandingBalance value being equal to 0. Currently, I am able to successfully update the "outstandingBalance", but I want to automatically change the status if it reaches 0. Below is the c ...

Designing functions with HTML

I have been working on creating a Coffeescript function that incorporates common HTML for an object that is frequently used on my page. To make the content dynamic, I am passing a variable to the function which will be replaced each time it is called. Unfo ...

Scroll indefinitely, obliterate and regenerate elements as you scroll

I have a unique issue that I need advice on from experts in this field. On my website, I have a Tree with infinite scroll functionality. The tree's image is iterative and the number of iterations depends on the data source provided. The data source ...

Enhance your Rails 5 application with a dynamic live search feature powered by Keyup. Say goodbye to

Currently, I have a Rails 5.1.3 application with a simple contact model that stores names and phone numbers. To enable searching within the index view/page, I am utilizing Ransack. A keyup event listener written in Coffeescript captures user input as they ...

Tips for ensuring the page remains functional with the signOut feature even after a refresh

I am facing an issue with my website. On the home page, I have a sign-in and sign-out column. Then, on the user page, there is a sign-up form. When I sign out, it works fine but upon refreshing the page, it still shows as if the user is not signed out. Can ...

What is the correct way to route requests to /api/ressource in a production environment?

In my development environment, I have set up a webpack dev configuration where my front-end server runs on port 8080 and my backend server runs on port 3000. Here is how I configured my webpack dev server: proxy: { '/api': 'http://localh ...

Tips for implementing Javascript form validation

While working on a Django form, I encountered an issue with implementing javascript logic. My goal is to submit the form if the input field is not empty. However, I am struggling to determine how to identify the id of {{form.value}}. <form id = " ...

Develop objects with a fixed position - three.js

I am currently working on a game utilizing the three.js library and I have a specific requirement. I would like to incorporate a small "panel" on the screen that remains stationary regardless of the user's navigation through the 3D environment. Essent ...

Styling a Pie or Doughnut Chart with CSS

I am working on creating a doughnut chart with rounded segments using Recharts, and I want it to end up looking similar to this: Although I have come close to achieving the desired result, I am encountering some issues: Firstly, the first segment is over ...

What is the correct way to utilize the karma-ng-html2js-preprocessor?

I'm working on a directive called stat24hour: angular .module('app') .directive('stat24hour', stat24hour); function stat24hour(req) { var directive = { link: link, template: 'scripts/widgets/templ ...

retrieving data from a php file using ajax for a post request

Utilizing ajax, I have invoked the page search.php: function search(){ var title=$("#search").val(); if(title!=""){ $.ajax({ type:"post", url:"sear ...

Replacing text within a paragraph using D3.js

Is it possible to develop a D3 function that can choose a paragraph, delete its content, and replace it with new text? If so, what would be the most effective way to accomplish this? I attempted the following: d3.select("#triggerButton") .on("clic ...

Animating a Canvas to Follow Mouse Coordinates

I am looking for a way to animate a circle moving towards specific coordinates, similar to the game . I have attempted using the jquery animate() function, but it is too slow due to the constant updating of the target coordinates. Is there a faster metho ...