To upgrade the dependencies in your package.json to the latest versions, you have several options. Here's a systematic approach:
# Check which packages are outdated
npm outdated
# Update packages within the version range in package.json
npm update
# Update to the latest versions (including major versions)
npm update --latestThis tool specializes in updating package.json dependencies to the latest versions:
# Install npm-check-updates
npm install -g npm-check-updates
# Check for updates without modifying package.json
ncu
# Update all dependencies in package.json to the latest versions
ncu -u
# Then install the updated packages
npm installIf you want more control, you can update specific packages:
# Update a specific package to latest
npm install package-name@latest
# Update multiple specific packages
npm install package1@latest package2@latestYou already have an upgrade.sh script that we created earlier. You can run it for an interactive upgrade process:
./upgrade.shFor a production project, consider this safer approach:
-
Create a git branch for the upgrade
git checkout -b dependency-upgrade
-
Update dependencies in batches by type
# Update development dependencies first ncu -u -f "/eslint|babel|webpack/" npm install # Update utility libraries ncu -u -f "/chalk|minimist|uuid/" npm install # Update React-related packages ncu -u -f "/react|jsx/" npm install
-
Run tests after each batch
npm test -
Commit working changes
git commit -am "Update dependencies: [category]"