# Common Shakapacker Upgrade Guides This document provides step-by-step instructions for the most common upgrade scenarios in Shakapacker projects. **📖 For configuration options, see the [Configuration Guide](./configuration.md)** ## Table of Contents - [Upgrading Shakapacker](#upgrading-shakapacker) - [Migrating Package Managers](#migrating-package-managers) - [Yarn to npm](#yarn-to-npm) - [npm to Yarn](#npm-to-yarn) - [Migrating to pnpm](#migrating-to-pnpm) - [Migrating from Babel to SWC](#migrating-from-babel-to-swc) - [Migrating from Webpack to Rspack](#migrating-from-webpack-to-rspack) --- ## Upgrading Shakapacker > **⚠️ Important:** Shakapacker is both a Ruby gem AND an npm package. **You must update BOTH** when upgrading. Shakapacker consists of two components that must be updated together: 1. **Ruby gem** - provides Rails integration and view helpers 2. **npm package** - provides webpack/rspack configuration and build tools ### Upgrade Steps #### 1. Update `Gemfile` ```ruby gem "shakapacker", "9.3.0" # or the version you want to upgrade to ``` **Pre-release versions:** Ruby gems use dot notation (e.g., `"9.3.0.beta.1"`) #### 2. Update `package.json` ```json { "dependencies": { "shakapacker": "9.3.0" } } ``` **Pre-release versions:** npm uses hyphen notation (e.g., `"9.3.0-beta.1"`) #### 3. Run bundler and package manager ```bash bundle update shakapacker yarn install # or npm install, pnpm install, bun install ``` #### 4. Test your build ```bash bin/shakapacker bin/shakapacker-dev-server ``` ### Why Both Must Be Updated - **Mismatched versions can cause build failures** - The Ruby gem expects specific configuration formats from the npm package - **Feature compatibility** - New features in the gem require corresponding npm package updates - **Bug fixes** - Fixes often span both Ruby and JavaScript code ### Version Format Differences Note that pre-release versions use different formats: | Component | Stable Version | Pre-release Version | | ------------ | -------------- | ------------------- | | Gemfile | `"9.3.0"` | `"9.3.0.beta.1"` | | package.json | `"9.3.0"` | `"9.3.0-beta.1"` | ### Finding the Latest Version - **Ruby gem:** Check [RubyGems.org](https://rubygems.org/gems/shakapacker) - **npm package:** Check [npmjs.com](https://www.npmjs.com/package/shakapacker) - **Releases:** See [GitHub Releases](https://github.com/shakacode/shakapacker/releases) ### Major Version Upgrades For major version upgrades, always consult the version-specific upgrade guides for breaking changes and new features: - [V9 Upgrade Guide](./v9_upgrade.md) - Upgrading from v8 to v9 (includes CSS Modules changes, SWC defaults, and more) - [V8 Upgrade Guide](./v8_upgrade.md) - Upgrading from v7 to v8 - [V7 Upgrade Guide](./v7_upgrade.md) - Upgrading from v6 to v7 - [V6 Upgrade Guide](./v6_upgrade.md) - Upgrading from v5 to v6 > **💡 Note:** Major version upgrades may include breaking changes. The steps above cover the basic gem/package updates that apply to all versions, but you should always review the version-specific guide for additional migration steps. --- ## Migrating Package Managers ### Yarn to npm Migrating from Yarn to npm is straightforward as both use similar package management concepts. #### 1. Remove Yarn lock file ```bash rm yarn.lock ``` #### 2. Install dependencies with npm ```bash npm install ``` This will create a new `package-lock.json` file. #### 3. Update scripts (if necessary) Review your `package.json` scripts and any deployment scripts that may reference `yarn` commands. Replace them with npm equivalents: ```json { "scripts": { "build": "shakapacker", "dev": "shakapacker-dev-server" } } ``` #### 4. Update CI/CD pipelines If you have CI/CD pipelines, update them to use `npm install` instead of `yarn install`. #### 5. Test your build ```bash npm run build ``` #### Common npm equivalents | Yarn Command | npm Equivalent | | -------------------------- | ---------------------------------- | | `yarn` | `npm install` | | `yarn add ` | `npm install ` | | `yarn add --dev ` | `npm install --save-dev ` | | `yarn remove ` | `npm uninstall ` | | `yarn run