How to update npm package's dependency? - npm

I am trying to update dependency of package I am installing trough npm.
When I install appium package, I get version 1.22.0 which is correct. But this package also have dependencies that getting regular updates on github and are propagated on npmjs.
But when I install main package, dependency is not latest.
For example, I need to update appium-espresso-driver dependency of appium to 1.50.1, but everytime I install appium, dependency is only 1.45.3, even when appium have ^1.0.0 in package.json
How to update this? Do I need to wait for appium package to be bumped?

If you want to update all the packages to the latest version and you are using npm, you can see this documentation npm-update, but the short answer is:
npm update
This helps to update every package of the project, you can do it in the root folder, and update everything in the package.json.
If you want to update everything to a latest version, you can use npm-check-updates, this will check the latest version of the packages that you have installed on package.json, I will show you the easy steps to install this but you can go through the documentation of the module in here:
npm install -g npm-check-updates
This will install you the package, then after that you need to run in in the root folder:
ncu -u
So after that command it will update all the packages in the package.json but not install them, so after running ncu -u you need to run again:
npm install
To install the new versions of the package.

Related

How to Update Angular Cli

Just to give you some context.
I was running a project and after ng serve I was getting this warning message:
our global Angular CLI version (9.1.4) is greater than your local
version (1.0.0). The local Angular CLI version is used.
I googled and figured out I should update angular cli with the following command.
npm install --save -dev #angular/cli#latest
After that I am getting the following error when trying to build the project:
The build command requires to be run in an Angular project, but a project definition could not be found
Any help will be much appreciated.
After reading some issues reported on the GitHub repository, I found the solution.
In order to update the angular-cli package installed globally in your system, you need to run:
npm uninstall -g angular-cli
npm install -g #angular/cli#latest
Depending on your system, you may need to prefix the above commands with sudo.
Also, most likely you want to also update your local project version, because inside your project directory it will be selected with higher priority than the global one:
rm -rf node_modules
npm uninstall --save-dev angular-cli
npm install --save-dev #angular/cli#latest
npm install
After updating your CLI, you probably want to update your angular version too
Note: if you are updating to Angular CLI 6+ from an older version, you might need to read this
Edit: In addition, if you were still on a 1.x version of the cli, you need to convert your angular-cli.json to angular.json, which you can do with the following command:
ng update #angular/cli --from=1.7.4 --migrate-only
check here for more details.

npm install not updating package to the latest dist-tag

I am publishing artifact to npm repository with a custom tag 'dev-latest'. After executing npm install in a project where I have this dependency defined, the latest version is not updated.
After new artifact is published I see that dev-latest points to the latest version:
npm view #kosmos/equote-lib dist-tags
{ 'dev-latest': '1.0.0-dev20190125.1',
latest: '1.0.0-rel20190122.0',
'rel-latest': '1.0.0-rel20190123.0' }
Locally i have installed previous version. In my package.json my dependency is defined:
"#kosmos/equote-lib": "dev-latest",
after executing npm install to update whole project my package is not updated to the latest version.
When I do npm install #kosmos/equote-lib#dev-latest it will update it but also change my package.json entry to the specific package version.
Other solution is to remove node_modules and the I will get latest version as well.
I would expect that using tag will remove the need of specifying the version in package.json Is there a way to implement the desired behavior ?
I think I found the good answer here: https://stackoverflow.com/a/19824154/1347496
Basically in case you have already installed the modules locally you should use npm update to update one/all dependencies. In my case while using tags I do
npm update --no-save
to not to overwrite my package.json

How do I install webpack version 4.19.1?

My system already has webpack version 4.27.5, but I need to uninstall this version and then use an older version 4.19.1, instead. I'm using Ubuntu.
I've run the command:
npm uninstall <web package>
but my issue was not resolved.
I recommend you to create a .npmrc file and add it
save-exact=true
This will prevent you from get packages like "^4.19.1", which AFAIK this means, get any package above 4.19.1
and then just install the needed package using the following command
npm install webpack#4.19.1 --save-dev

How to update package.json dependencies when linking from globally installed packages?

I organize my development projects installing globally all the npm packages I need with:
npm -g install [package]
Then I simlink individually the dependencies I need for each project with:
npm link [package]
This way, I have to update manually each package.json file to add the dependency, and when I upgrade the global node_modules I have to go and update all the package.json projects.
For this first issue I tried npm link [package] --save but it doesn't add the dependency to package.json and if I use npm install [package] --save it installs the package locally, thing I don't want.
Is there any way to be able to not have to configure package.json manually and be able to have an updated configuration of package.json from many different projects in a easier way?
Yes you can install npm-check-updates, you can find the install and guide here:
https://www.npmjs.com/package/npm-check-updates
when running 'ncu' on the command-line in your root-folder where your package.json is, it will list the packages that can be updated and by running 'ncu -u' on the command-line it updates all the packages for you.

npm install only if package missing or out-of-date compared to package.json

I want to be able to compare my locally installed packages against my project package.json file without making a call against the npm online repo. If there is a package that is out of date based on the package.json file, then and only then will it go to the npm online repo and install the package.
The reason for this is that I want to be able to update the package.json file to require a newer version of a package, commit this change to the project repo and when other developers on the team get latest their npm package is updated. I do not want to slow down the process if everything is up-to-date or cause the build to fail if access to the npm repo or the internet is down.
I am wondering if this is an already solved use-case or do I need to parse the package.json file and compare it to a "npm ls" output myself?
you will need to setup a local repository (by duplicating the NPM couchdb localy)
( see https://stackoverflow.com/a/7577265/406458)
then you could use npm-check-updates.
npm-check-updates will give you a list of packages that can be updated in your package.json file see
https://www.npmjs.org/package/npm-check-updates
$ npm-check-updates
"connect" can be updated from 2.8.x to 2.11.x (Installed: 2.8.8,
Latest: 2.11.0) "commander" can be updated from 1.3.x to 2.0.x
(Installed: 1.3.2, Latest: 2.0.0)
Run 'npm-check-updates -u' to upgrade your package.json automatically
Check global npm packages for updates:
$ npm-check-updates -u