NestJS v9 -> v10

The project was created with NestJS v9 and now it can be upgraded to v10. To achieve this using ncu, we should follow these steps:

  • Install the latest node LTS version through nvm and activate it

nvm install lts
nvm use lts
  • Install yarn (if you use it) and nest globally

npm i -g yarn @nestjs/cli
  • Install ncu globally

npm i -g npm-check-updates
  • Inside the project directory, use ncu to check available updates

ncu
  • Update everything

ncu -u
  • Change the eslint in package.json back to v8, due to many breaking changes

"eslint": "^8.0.0"

Then, we should update the .gitignore file, by putting at the end of the #compiled output section:

/build

And after the # IDE - VSCode section:

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

In the tsconfig.json file, alter the target field to ES2021.

Finally, delete yarn.lock and node_modules, and run yarn to actually update the dependencies.

If you are on Windows and want to switch the line break of your files back from LF to CRLF, you may perform the following steps:

  • In the file .prettierrc, set endOfLine to "crlf"

  • In the terminal, run the following commands

    • yarn format

    • git config core.autocrlf true

  • Set endOfLine back to "auto"

Commit - Upgrading from NestJS v9 to v10

Last updated