---
sidebar_position: 3
---

# Upgrading

## Upgrade with command

Modern.js provides the `upgrade` command to support upgrading the project to the latest version of Modern.js.

Run the `upgrade` script in the project:

import { PackageManagerTabs } from '@theme';

<PackageManagerTabs command="run upgrade" />

```bash
> modern upgrade

[INFO] [Project Type]: Web App
[INFO] [Modern.js Latest Version]: x.y.z
[INFO] Upgrade Modern.js package version success!
```

You can see that the dependencies in the project's `package.json` have been updated to the latest version.

:::tip
If the `upgrade` command is not declared in the project's `package.json`, you can execute `npx modern upgrade` as an equivalent alternative.
:::

import UpgradeFaq from '@site-docs-en/components/upgrade-faq';

<UpgradeFaq />

## Upgrade to a specified version

All packages of Modern.js are currently released with a **uniform version number**.

import ReleaseNote from '@site-docs-en/components/release-note';

<ReleaseNote />

:::tip
When upgrading, you need to upgrade all packages provided by Modern.js, rather than upgrading some dependencies.
:::

## Version Management Strategy

In Modern.js projects, we recommend that all officially provided dependencies use fixed version, and avoid using `^` or `~` for range declarations. For example:

```json
{
  "dependencies": {
    "@modern-js/app-tools": "x.y.z"
  }
}
```

This ensures that the versions of dependencies are fully determined, thereby guaranteeing build consistency and predictability.


## Lock nested dependency

When a nested dependency of the project has a problem and Modern.js cannot be updated immediately, you can use the package manager to lock the version of the nested dependency.

### pnpm

For projects using pnpm, add the following configuration to the `package.json` in the **root directory** of the project, and then run `pnpm install` again:

```json title="package.json"
{
  "pnpm": {
    "overrides": {
      "package-name": "^1.0.0"
    }
  }
}
```

### Yarn

For projects using Yarn, add the following configuration to the `package.json` in the **root directory** of the project, and then run `yarn install` again:

```json title="package.json"
{
  "resolutions": {
    "package-name": "^1.0.0"
  }
}
```

### Npm

For projects using Npm, add the following configuration to the `package.json` in the **root directory** of the project, and then run `npm install` again:

```json title="package.json"
{
  "overrides": {
    "package-name": "^1.0.0"
  }
}
```

:::info
For Monorepo repositories, you can only lock dependency versions in the `package.json` in the root directory of the project, and it will affect all packages in the Monorepo.

:::
