Skip to content
Skills Library
Programming · Analysis

swc-plugin-compatibility

/swc-plugin-compatibility

Diagnose and fix Lingui SWC plugin compatibility errors with Next.js, Vite, Rspack, or other SWC runtimes. Use when seeing errors like "failed to invoke plugin", "failed to run Wasm plugin transform", "Failed to deserialize program received from host", "Failed to execute SWC plugin", "out of bounds memory access", or "LayoutError" during builds with @lingui/swc-plugin — or when macros are silently not transformed (build succeeds but Trans/t render as raw untranslated output).

Repository
skills ↗
Licence
MIT
Last repository change
20.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
7
Deprecation

No signals detected. Repository changed on 20.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Diagnose and fix Lingui SWC plugin compatibility errors with Next.js, Vite, Rspack, or other SWC runtimes. Use when seeing errors like "failed to invoke plugin", "failed to run Wasm plugin transform", "Failed to deserialize program received from host", "Failed to execute SWC plugin", "out of bounds memory access", or "LayoutError" during builds with @lingui/swc-plugin — or when macros are silently not transformed (build succeeds but Trans/t render as raw untranslated output).

Triggers from the description

failed to invoke pluginfailed to run Wasm plugin transformFailed to deserialize program received from hostFailed to execute SWC pluginout of bounds memory accessLayoutError
Original author description

Diagnose and fix Lingui SWC plugin compatibility errors with Next.js, Vite, Rspack, or other SWC runtimes. Use when seeing errors like "failed to invoke plugin", "failed to run Wasm plugin transform", "Failed to deserialize program received from host", "Failed to execute SWC plugin", "out of bounds memory access", or "LayoutError" during builds with @lingui/swc-plugin — or when macros are silently not transformed (build succeeds but Trans/t render as raw untranslated output).

How it works

  1. Why This Happens
  2. How to Fix
  3. Keeping It Working
  4. Example: Next.js Configuration
  5. Example: .swcrc Configuration
  6. Native Transform on Vite
  7. Example: Vite Configuration (SWC plugin)
  8. Silent Failure: Wrong Plugin Entry Shape
  9. What If No Compatible Version Exists?
Original SKILL.md headings · 191 lines, 1,432 words
SKILL.md preview
---
name: swc-plugin-compatibility
description: Diagnose and fix Lingui SWC plugin compatibility errors with Next.js, Vite, Rspack, or other SWC runtimes. Use when seeing errors like "failed to invoke plugin", "failed to run Wasm plugin transform", "Failed to deserialize program received from host", "Failed to execute SWC plugin", "out of bounds memory access", or "LayoutError" during builds with @lingui/swc-plugin — or when macros are silently not transformed (build succeeds but Trans/t render as raw untranslated output).
---

# SWC Plugin Compatibility

If you see errors like these during your build:

```
failed to invoke plugin on 'Some("/app/src/file.ts")'
failed to run Wasm plugin transform. Please ensure the version of `swc_core` used by the plugin is compatible with the host runtime.
    swc_plugin_runner: <n>
: Failed to deserialize program received from host
Failed to execute SWC plugin                      (Next.js / Turbopack wording of the same failure)
RuntimeError: out of bounds memory access         (older hosts)
LayoutError called Result::unwrap()               (older hosts)
```

**This is NOT a bug in your code or in Lingui.** The installed `@lingui/swc-plugin` was built against an `swc_core` version your SWC host cannot run.

## Why This Happens

Every `@lingui/swc-plugin` release is compiled against one pinned `swc_core` version — the plugin's [compatibility table](https://github.com/lingui/swc-plugin/blob/main/packages/lingui-macro/README.md#compatibility) lists them. The **host** (Next.js's bundled SWC, or the `@swc/core` that `@vitejs/plugin-react-swc` / Rspack resolves) accepts plugins from a range of `swc_core` versions. Outside that range the Wasm plugin cannot deserialize the AST it is handed, and the build fails on every file that uses a macro.

SWC has stabilised the plugin ABI over time, so mismatches are rarer than they were, but hosts still move past plugins and plugins past hosts (see lingui/swc-plugin [#250](https://github.com/lingui/swc-plugin/issues/250) and [#253](https://github.com/lingui/swc-plugin/issues/253) for one of each). The pairing is something to check, never assume.

## How to Fix

### Step 1: Identify the host and its resolved version

| Signal in the project | Host | Read the version from |
|---|---|---|
| `next` in dependencies, no `.babelrc` | Next.js's bundled SWC | `npm ls next` |
| `@vitejs/plugin-react-swc` | `@swc/core` | `npm ls @swc/core` — the **lockfile resolution**, not the caret range the plugin declares |
| Rspack / `@swc/core` directly | `@swc/core` | `npm ls @swc/core` |

Next.js embeds SWC and ignores any `@swc/core` in `package.json`; only the Next.js version decides its `swc_core`. On Vite, two projects with identical `package.json` can resolve different `@swc/core` versions — the lockfile is the source of truth.

**On Vite, the first fix is the native transform** ("Native Transform on Vite" below): `@lingui/vite-plugin` transforms the macros with its own prebuilt binary, outside the host's SWC, so there is no `swc_core` pairing and nothing to pin. The steps that follow are for Next.js, Rspack, and Vite builds the native binary can't run on.

### Step 2: Choose the plugin version

1. Read the host's accepted `swc_core` range. The error message usually prints a `https://plugins.swc.rs/versions/from-plugin-runner/<n>` URL — open it in a browser; for Next.js, select runtime `next` and the resolved version on https://plugins.swc.rs. The site is client-rendered, so a plain fetch returns an empty page; the fallback is the host's own pin: for Next.js, `swc_core` in the root `Cargo.toml` of the `vercel/next.js` tag (`v<version>`), for `@swc/core`, its GitHub release notes.
2. In the plugin's compatibility table, take the **newest** `@lingui/swc-plugin` whose `swc_core` falls inside that range.
3. Check its peer: `npm view @lingui/swc-plugin@<version> peerDependencies`. Each plugin major requires the matching `@lingui/core` major as a **required** peer (a newer plugin major may also admit the previous core major). A candidate whose peer excludes the installed `@lingui/core` is not a candidate — the install fails with `ERESOLVE` instead of the build failing. Pick the next-newest that passes, or go to "What If No Compatible Version Exists?".

The compatibility site has lagged behind releases before. When the table and the site disagree, or the host is newer than either lists, decide by building: try the newest plugin, then step back one `swc_core` row at a time until a macro-using file compiles.

Hosts drift independently, so two hosts in one repo (a Next.js app and a Vite app) can legitimately need two different plugin versions.

### Step 3: Pin exactly and confirm

```json
{
  "devDependencies": {
    "@lingui/swc-plugin": "<exact version>"
  }
}
```

Use an **exact version** (no `^` or `~`) so a routine dependency bump cannot move it. Done when the build passes on a file that uses a macro **and** the rendered output shows translated text rather than raw macro source.

## Keeping It Working

1. **Pin the plugin exactly** and exclude it from Renovate/Dependabot auto-merge; bump it deliberately, after checking the compatibility table.
2. **Treat host upgrades as plugin upgrades.** Hosts change `swc_core` in minor and patch releases, so a Next.js or `@vitejs/plugin-react-swc` bump needs the same check — put both packages in one update group.
3. **Build after any upgrade that touches SWC or the plugin.** The build, not the changelog, is the confirmation.

`@lingui/swc-plugin` does not track the other `@lingui/*` versions; it releases on its own cadence, so its version number carries no information about which `@lingui/core` it pairs with beyond the peer field.

## Example: Next.js Configuration

```js
// next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    swcPlugins: [
      ['@lingui/swc-plugin', {
        // Plugin options
      }],
    ],
  },
};

export default nextConfig;
```

## Example: .swcrc Configuration

```json
{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "experimental": {
      "plugins": [
        ["@lingui/swc-plugin", {}]
      ]
    }
  }
}
```

## Native Transform on Vite

```ts
// vite.config.ts — no @lingui/swc-plugin
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc"; // or @vitejs/plugin-react
import { lingui } from "@lingui/vite-plugin";

export default defineConfig({
  plugins: [react(), lingui({ macroTransform: true })],
});
```

Requirements: `@lingui/vite-plugin` 6.9.1+, and a build machine with a prebuilt `@lingui/native-tools` binary (macOS, Windows, Linux glibc/musl on x64/arm64). There is no WASM fallback, so browser sandboxes such as StackBlitz WebContainers still need the SWC or Babel plugin.

## Example: Vite Configuration (SWC plugin)

```ts
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { lingui } from "@lingui/vite-plugin";

export default defineConfig({
  plugins: [
    react({ plugins: [["@lingui/swc-plugin", {}]] }),
    lingui(),
  ],
});
```

## Silent Failure: Wrong Plugin Entry Shape

Every SWC plugin entry must be a `[name, options]` **tuple**, even with empty options. Passing the plugin name as a bare string silently disables the macro transform: the build succeeds, but `<Trans>` never resolves and messages render as raw macro output.

```ts
// ❌ Silently does nothing
react({ plugins: ["@lingui/swc-plugin"] })

// ✅ Tuple with options object
react({ plugins: [["@lingui/swc-plugin", {}]] })
```

The same applies to Next.js `swcPlugins` and `.swcrc` `plugins` arrays.

Fixing the shape is the fix. On Vite, close by offering the native transform ("Native Transform on Vite") as a follow-up the user chooses: it drops the SWC plugin for good.

## What If No Compatible Version Exists?

When no plugin version that installs beside the project's `@lingui/core` fits the host, make an explicit choice rather than guessing:

1. **Move the host** to a version whose `swc_core` range has a matching plugin (usually forward: newer hosts accept newer plugins)
2. **Switch to the Babel transform** (`@lingui/babel-plugin-lingui-macro`) — see the caveats below
3. Open an issue or PR at https://github.com/lingui/swc-plugin

Forcing the install (`--legacy-peer-deps`) or downgrading `@lingui/core` to satisfy an old plugin's peer are not on this list: the first hides the mismatch until the build, the second regresses the runtime to please a build tool.

### Babel Fallback on Next.js

```bash
npm install -D @lingui/babel-plugin-lingui-macro babel-plugin-macros @babel/types
```

```json
// .babelrc
{ "presets": ["next/babel"], "plugins": ["macros"] }
```

Remove the `experimental.swcPlugins` entry. Three things the Babel path needs that the SWC plugin did not:

1. **`@babel/types` installed explicitly.** Next bundles its own Babel and does not expose it to plugins; without it the build fails with `Cannot find package '@babel/types'`.
2. **A `lingui.config.ts` (or `.js`/`.mjs`).** The Babel macro reads it at compile time; the SWC plugin never did, so a project that got by without one breaks here.
3. **Acceptance that `.babelrc` turns off Next's SWC compiler for the whole project** — Next prints `Disabled SWC as replacement for Babel because of custom Babel configuration`, and `compiler` options in `next.config` are ignored from then on. Builds get slower; prefer moving the host when that is an option.

### Babel Fallback Caveat: @vitejs/plugin-react 6

`@vitejs/plugin-react@6` dropped its internal Babel and **removed the `babel` option entirely**. On v6+, the classic form:

```ts
react({ babel: { plugins: ["@lingui/babel-plugin-lingui-macro"] } })
```

no longer works — a TypeScript config fails with TS2353 ("babel does not exist in type..."); a plain JS config is **silently ignored** and macros never get transformed.

Your options on Vite:

- Native transform: `lingui({ macroTransform: true })` with the stock React plugin — no Babel, no SWC plugin, no pin (preferred; see "Native Transform on Vite")
- Stay on SWC: `@vitejs/plugin-react-swc` + an exactly pinned `@lingui/swc-plugin` chosen by the steps above
- Run the macro as a standalone Babel pass (`@rolldown/plugin-babel` on Vite 8, `vite-plugin-babel` on Vite ≤ 7) — the lingui-framework-setup skill has the wiring
- Pin `@vitejs/plugin-react@^5`, which still supports the `babel` option

Versions

RepositoryScoreLicence
This page · lingui/skills100MIT
platformplatform/platformplatform100MIT

Database snapshot: 13.11.2026 · package version a0f50b538f6f (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100rspack
    Rspack is a Rust-based JavaScript bundler with a webpack-compatible config, loader and plugin API, built for much faster builds. Use when someone asks to "speed up webpack", "migrate from webpack to Rspack", "set up Rspack", "fast bundler for React and TypeScript", or "replace…
  • 100migrate-to-rspack
    Use when migrating an existing Meteor app to Rspack (Meteor 3.4+), or upgrading Rspack 1 to 2 on Meteor 3.6 beta. Triggers on nested imports, mainModule entry points, server-only apps, replacing fourseven:scss / meteor/less / coffeescript / jorgenvatle:vite / zodern:melte with…
  • 100swc
    SWC (Speedy Web Compiler) is a Rust-based compiler and minifier for JavaScript and TypeScript, used as a faster replacement for Babel and Terser. Use when a user asks to compile TypeScript or JSX with swc, configure .swcrc, replace babel-jest with @swc/jest, minify code, use the…
  • 100meteor-modern-build-stack
    Use when configuring or tuning the Meteor 3 modern build stack: SWC transpiler, SWC-based minifier, modern @parcel/watcher, web-arch skipping in development, .meteorignore, and Rspack integration. Triggers on package.json "meteor": { "modern": true }, .swcrc, swc.config.js,…
  • 100sync-modern-tool-versions
    Use when changing npm package or dependency versions used by Meteor's modern tooling, especially Rspack and SWC. Discovers and synchronizes manifests, lockfiles, install constants, compatibility floors, skeletons, E2E fixtures, and active documentation. Verifies repository…
  • 100swc-parser
    Parse JavaScript/TypeScript code into AST using SWC (Speedy Web Compiler). Use this for code analysis, transformation, or understanding JavaScript/TypeScript structure.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.