Robel Robel Lingstuyl
Robel Robel Lingstuyl

Reputation: 1591

Is there a recommended way to update NestJS?

I'm currently using 6.0.4, I'd like to get to 6.5.2. What is the best way to do this? Is there something in the CLI? Do I manually update each @nestjs package?

Current dependencies are:

    "@nestjs/common": "^6.0.4",
    "@nestjs/core": "^6.0.4",
    "@nestjs/microservices": "^6.0.4",
    "@nestjs/passport": "^6.1.0",
    "@nestjs/platform-express": "^6.0.4",
    "@nestjs/swagger": "^3.0.2",

Upvotes: 78

Views: 86356

Answers (13)

Leonardo Lima
Leonardo Lima

Reputation: 140

Use NCU (NPM Check Updates) package on interactive mode to select nestjs packages to update.

npx npm-check-updates -i

choose wich packages to update using ncu

Upvotes: 1

Yogesh Umesh Vaity
Yogesh Umesh Vaity

Reputation: 48129

The nest update command has been deprecated. The NestJS creator now recommends using the npm-check-updates package.

Using NPM

Install the npm-check-updates package:

npm i npm-check-updates

Now update the NestJS related packages:

npx ncu -u -f "/nestjs*/"

This command will update only the dependencies that have nestjs in their name in package.json

Then run:

npm install

After running the app, if you get the error: Cannot find module...

Install the packages manually one by one with the following commands:

npm i @nestjs/config

npm i @nestjs/jwt

npm i @nestjs/platform-express

npm i @nestjs/core

npm i @nestjs/common

npm i @nestjs/typeorm --force

Using Yarn

Install the npm-check-updates package:

yarn add npm-check-updates

Update the NestJS packages:

yarn npm-check-updates -u -f "/nestjs*/"

Then, to install the dependencies, simply run:

yarn

Upvotes: 14

Allen Wong
Allen Wong

Reputation: 1433

from v9 to v10, you may use ncu for package check

npm i -g npm-check-updates
ncu -u -f /^@nestjs/

but it won't change the package-lock.json, so you have to do npm install again

rm package-lock.json
rm -rf node_modules
npm install

Upvotes: 4

Baad
Baad

Reputation: 1

How I upgraded from 8 to 9 with yarn:

  • install yarn add npm-check-updates
  • then execute ncu u

Successfully updated in my case.

Upvotes: 0

Mohamed Ellili
Mohamed Ellili

Reputation: 31

The best way to upgrade nestjs from x version to 9 that i personnally used and it worked for me is : delete package-lock.json

delete node_module run :

npm cache clean --force
nvm i 16.13.0
nvm use default 16.13.0
npm i -g npm-check-updates
ncu -u
npm i

nestjs 9 use typeorm 0.3 You should update your files (Repository) check this: https://typeorm.io/changelog

Upvotes: 1

Ezequiel
Ezequiel

Reputation: 37

This works to update to version 9:

$ npm install -g @nestjs/cli
$ ncu -u
$ npm i

Upvotes: 1

greenchapter
greenchapter

Reputation: 136

I think actually the best solution is to use install npm-check and run npm-check -u. I have currently updated in that way from 8 to 9.

Upvotes: 0

Matt Walterspieler
Matt Walterspieler

Reputation: 2171

You can use the Nest CLI to update the dependencies:

$ npm install -g @nestjs/cli
$ nest update

You can also $ nest u

As Mick mentioned in his comment, you might have to add --force argument.

nest update --force

Update - July 7 2022

Since v9.0.0 release, the command update was removed. To upgrade your dependencies, you can use dedicated tools like ncu, npm update, yarn upgrade-interactive, etc.

Upvotes: 94

Ian Samz
Ian Samz

Reputation: 2119

I followed this answer

npm install -g @nestjs/cli
npx npm-check-updates "/nestjs*/" -u 

Upvotes: 19

Masih Jahangiri
Masih Jahangiri

Reputation: 10907

An answer for fast developers:

  1. npx nest update -f
  2. Follow docs.nestjs.com/migration-guide link to apply the changes required for the new version

Upvotes: 5

Chuong Tran
Chuong Tran

Reputation: 3431

Force update with the command:

nest update -f -t latest

nest info 



_   _             _      ___  _____  _____  _     _____
| \ | |           | |    |_  |/  ___|/  __ \| |   |_   _|
|  \| |  ___  ___ | |_     | |\ `--. | /  \/| |     | |
| . ` | / _ \/ __|| __|    | | `--. \| |    | |     | |
| |\  ||  __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/  \____/\_____/\___/


[System Information]
OS Version     : macOS Catalina
NodeJS Version : v12.16.1
NPM Version    : 6.13.4
[Nest Information]
platform-express version : 7.4.2
microservices version    : 7.4.2
common version           : 7.4.2
core version             : 7.4.2

You can check at this post

Nest Docs: nest update

Upvotes: 35

nerdy beast
nerdy beast

Reputation: 789

The way I handle this is to manually update each package. It's a little tedious but it gives you full control of what versions each package is set at.

I will usually create a "feature" branch in git, something like feature/upgrade where I'll update the packages

npm i @nestjs/common@latest @nestjs/core@latest ...

Try it out there, then merge that branch into master (or whatever your development branch is). Git removes the need for "copying" code from another directory, if the new package versions breaks something, you have time to fix them in the feature branch before rolling out to production.

Upvotes: 6

Preston
Preston

Reputation: 3528

Everything you want to know about upgrading with npm: NPM Upgrading

The best way to do a whole version upgrade in my experience is to install the version you want in a directory, say server/nestjs7, and then copy your code from the earlier version to the new one. Then just boot from inside /nestjs7 and you are good to go. Nice to have a fall back to the old version sometimes.

Upvotes: 1

Related Questions