swc-project/swc · error

corejs version other than 2 / 3

Error message

corejs version other than 2 / 3

What it means

`swc_ecma_preset_env` injects core-js polyfill imports and only implements usage-mode visitors for core-js major 2 and major 3. The `env.coreJs` config value is parsed into a semver `Version`; any other major reaches `_ => unimplemented!("corejs version other than 2 / 3")` — this site is the `Mode::Usage` branch at lib.rs:458.

Source

Thrown at crates/swc_ecma_preset_env/src/lib.rs:458

            Some(Mode::Usage) => {
                let mut r = match self.corejs {
                    Version { major: 2, .. } => {
                        let mut v = corejs2::UsageVisitor::new(self.targets.clone());
                        m.visit_with(&mut v);

                        v.required
                    }
                    Version { major: 3, .. } => {
                        let mut v = corejs3::UsageVisitor::new(
                            self.targets.clone(),
                            self.shipped_proposals,
                            self.corejs,
                        );
                        m.visit_with(&mut v);
                        v.required
                    }

                    _ => unimplemented!("corejs version other than 2 / 3"),
                };

                if regenerator::is_required(m) {
                    r.insert("regenerator-runtime/runtime.js");
                }

                r
            }
            Some(Mode::Entry) => match self.corejs {
                Version { major: 2, .. } => {
                    let mut v = corejs2::Entry::new(self.targets.clone(), self.regenerator);
                    m.visit_mut_with(&mut v);
                    v.imports
                }

                Version { major: 3, .. } => {
                    let mut v =
                        corejs3::Entry::new(self.targets.clone(), self.corejs, !self.regenerator);

View on GitHub (pinned to d7d7434666)

Solutions

  1. Set `env.coreJs` to "3" (or "2" only if you must match an old dependency tree)
  2. Verify the installed core-js package version matches the configured string
  3. Upgrade swc once support for the new core-js major lands; track the upstream issue

Example fix

// .swcrc before
{ "env": { "mode": "usage", "coreJs": "4" } }

// after
{ "env": { "mode": "usage", "coreJs": "3" } }
Defensive patterns

Strategy: validation

Validate before calling

// Validate coreJs config before invoking swc
const major = Number(String(config.env?.coreJs ?? '3').split('.')[0]);
if (major !== 2 && major !== 3) throw new Error(`coreJs ${config.env.coreJs} unsupported; use "2" or "3"`);

Prevention

When it happens

Trigger: Set `env.coreJs` to a version whose major is neither 2 nor 3 (e.g. "4") while `env.mode` is `usage` and polyfills are enabled.

Common situations: Copying config from Babel projects already on core-js 4; adopting a new core-js major before swc supports it; typos like `coreJs: "30"`.

Related errors


AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16). Data as JSON: /api/errors/3b6779dd29815ffd. Report an issue: GitHub.