Steps to update the package version in package.json file

If I remove a package from my project using the following command:

npm uninstall react     

The entry for this package in the package.json file does not disappear. Then, when I install a different version of this package like so:

npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a485f5b594e7a0b0f140a">[email protected]</a>

The new package version gets installed in node_modules, but the version in package.json remains unchanged. It still shows the old version that was present before the uninstallation.

Is there a way to delete/update/change the version directly in package.json via terminal?

Answer №1

Make sure to include the --save option when running both the install and uninstall commands.

By using --save during an uninstall, the package's entry will be removed from both package.json and node_modules. Conversely, when installing with --save, the package's details will be added to package.json and installed in node_modules.

Here is an example of how you should proceed:

npm uninstall react --save    
npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f98b9c989a8db9c8ccd7c9d7c9">[email protected]</a> --save

Answer №2

When it comes to updating the version number within the package.json file, it's a straightforward process. All you need to do is locate the specific line in the package.json file and modify it to reflect the new version you want to use:

"react": "16.8.0",

After making this change, be sure to save the file and then execute the command npm install. By checking the package-lock.json file, you can confirm the exact version that has been installed.

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

Issue with Canvas.doDataUrl not functioning properly in presence of an image on canvas

It seems like the code I have tried only works for local images. Can someone share a working code snippet for this? Here is what I've attempted: var base_image = new Image(); base_image.src = ("/img.png"); base_image.onload = function(){ var co ...

Is it possible to pass the index variable of a for loop to a different function?

As a current bootcamp student, I have a question about passing the index of a for loop to another function. Specifically, I am trying to fetch data from an API (which provides me with a random cryptocurrency from an array) 4 times and then pass that data ...

Learn how to display only certain elements when triggered by the click of another

I have developed a tab system where each tab contains a unique set of questions and answers. The structure of the tabs is exactly as I envisioned, but I am facing challenges with toggling the display of answers when their respective questions are clicked. ...

Bootstrap Tags Input is unable to function properly with data stored locally

I am currently working on developing a Project Manager tool that allows for the addition of multiple individuals to a single project. To accomplish this, I decided to incorporate the use of Bootstrap Tags Input by following the examples provided for Typeah ...

Dealt with and dismissed commitments in a personalized Jasmine Matcher

The Tale: A unique jasmine matcher has been crafted by us, with the ability to perform 2 key tasks: hover over a specified element verify the presence of a tooltip displaying the expected text Execution: toHaveTooltip: function() { return { ...

Best practice for integrating Typescript into an established ASP.NET 4 Webforms project

Currently, I am working on an older asp.net 4.0 Webforms project using Visual Studio 2015. My goal is to transition from using Javascript to TypeScript for certain client side code tasks. While I have experience using TypeScript in projects outside of Vis ...

What are the benefits of adding member functions to the data structures of React.js store?

Using React.js and Typescript, I store plain Javascript objects in the React.js store. These objects are sometimes received from the server without any member functions, but I wish to add functions for better organization. Instead of having to rely on exte ...

Encountering errors while running the 'npm install' and 'npm i -g @angular/cli' commands resulting

After cloning an angular repository and running npm i, I encountered the following error: PS C:\projects\FIFA\skeleton> npm i npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681b071d1a0b0d4 ...

Encountering a Npm ERR! when deploying Angular 6 to Heroku due to missing Start script

I am experiencing an issue with my simple angular 6 app after deploying it to Heroku. When I check the logs using the command heroku logs, I encounter the following error: 2018-07-15T00:45:51.000000+00:00 app[api]: Build succeeded 2018-07-15T00:45:53.9012 ...

Finding a specific object within an array of objects by searching through a key value pair

In my collection, I have an array of objects structured as follows: [{ "businessunit": [{ "Area": [{ "Asset": [{ "Wells": { "Well": "Well 11" }, "name": "Field ...

A combination of Tor Browser, Selenium, and Javascript for

I have been attempting to use selenium with Tor, but unfortunately it is not functioning correctly. I have come across a library that allows for this functionality, however, it appears to only work with Python. Is there a way to accomplish this using Jav ...

Vulnerability CVE-2022-23529 (High severity) has been identified in the package jsonwebtoken-8.5.1.tgz linked to IBM Cloud App

There is a high vulnerability related to jsonwebtoken in the ibmcloud-appid package. I have already updated ibmcloud-appid to the latest version, but the jsonwebtoken version in package-lock.json remains at 8.5.1. The recommended update for jsonwebtoken ...

Changes made to attribute values through Ajax success function are not immediately reflected and require a manual page refresh to take effect

Whenever I attempt to rename my object using an Ajax request triggered by a click event, followed by updating its element's attribute with the new name in the success function, I encounter a partial issue. Upon inspecting the element on Chrome, post- ...

Obtaining the initial row information from jqGrid

If I use the getRowData method, I can retrieve the current cell content instead of the original data before it was formatted. Is there a way to access the original content before any formatting transformations are applied? Just so you know, I am filling t ...

Merge two distinct arrays of objects based on a shared field

I have two arrays of objects that I need to merge, with the expected output as: [ { "scenario": [ { "errorname": "Error 01", "status": 5, "desc_1" : "test", "desc_2" : "testing" }, ...

"Implementing interactive arrow buttons in a horizontal navigation bar using HTML, CSS, and JavaScript

Seeking advice on creating a horizontal navigation bar with arrow buttons at the sides, such as the one shown below. Despite extensive research, I have not found the exact solution I am looking for. This will be implemented in my Vue.js project. |<| P ...

Javascript: Harnessing Textbox Arrays for Improved Functionality

Check out the form displayed below. <form id="upload_form" enctype="multipart/form-data" method="post"> <input type="text" name="name[]" id="name"><br> <input type="text" name="name[]" id="name"><br> <input type="fil ...

Issue with utilizing addEventListener("load") in Firefox in conjunction with <iframe>

I've encountered an issue with my iframe when it is used as the target for a form. In all major browsers, except for Firefox, the iframe successfully removes the main element upon pressing the submit button. However, in Firefox, the main element is re ...

What is the button that switches the bootstrap modal?

With my bootstrap modal form, I have multiple buttons that trigger it as shown below: <a href="javascript:void(0)" data-toggle="modal" data-target="#specialoffer"> <button class="green full" id="button1">Ask Question</button> </a& ...

Error: JSON parsing error encountered due to an unexpected token 'U' while trying to read a file with

Currently, I am utilizing Node.js version 12.14.1 and encountering a problem while attempting to parse a JSON file that includes the \U0001f970 character. The file's content that needs to be read and parsed is as follows: {"randomKey": ...