If you frequently update dependencies in small batches, you will avoid large and painful updates later. Then again, if you don't have good test coverage, it's hazardous to update dependencies at any time.
Delete any unwanted version constraints from your Gemfile and run:
bundle updateRun the commands below from the directory that contains your package.json. In current React on
Rails apps, that is usually the app root rather than a client/ subdirectory.
Check for outdated versions of packages:
pnpm outdatedUse the equivalent npm outdated or yarn outdated command if your app uses a different package
manager. Read CHANGELOGs of major updated packages before you update. You might not be ready for
some updates.
Option 1: Using npm-check-updates (Recommended)
-
Install npm-check-updates
-
Run these commands. You may or may not need to
rm -rfyournode_modulesdirectory.pnpm dlx npm-check-updates -u -a pnpm install
Some combinations that I often run:
-
Remove old installed
node_modulesso you only get what corresponds topackage.json:pnpm dlx npm-check-updates -u -a && rm -rf node_modules && pnpm install
Use the equivalent npx npm-check-updates -u -a && npm install or yarn dlx npm-check-updates -u -a && yarn install flow if your app does not use pnpm.
Option 2: Using your package manager's upgrade command
To update all dependencies:
pnpm up --latestTo upgrade a specific package:
pnpm up [package] --latestEquivalent commands for other package managers are npm update / npm install <package>@latest
and yarn upgrade / yarn add <package>@latest.
Typically, you can add your Node dependencies as you normally would:
pnpm add module_name@version
# or for dev dependencies
pnpm add -D module_name@versionIf your app uses npm or yarn, use the corresponding npm install or yarn add command in the
same directory as package.json.
Confirm that the hot replacement dev server and the Rails server both work after updating dependencies.