babel/babel · error

Caching has already been configured with .never()

Error message

Caching has already been configured with .never()

What it means

Thrown by CacheConfigurator.forever() when this._never is already true. Babel cache modes are mutually exclusive: once you declare .never() the configurator forbids switching to .forever(), because the two modes produce incompatible cache entries (never = re-evaluate every time, forever = evaluate once and memoise permanently).

Source

Thrown at packages/babel-core/src/config/caching.ts:279

  }

  simple() {
    return makeSimpleConfigurator(this);
  }

  mode() {
    if (this._never) return "never";
    if (this._forever) return "forever";
    if (this._invalidate) return "invalidate";
    return "valid";
  }

  forever() {
    if (!this._active) {
      throw new Error("Cannot change caching after evaluation has completed.");
    }
    if (this._never) {
      throw new Error("Caching has already been configured with .never()");
    }
    this._forever = true;
    this._configured = true;
  }

  never() {
    if (!this._active) {
      throw new Error("Cannot change caching after evaluation has completed.");
    }
    if (this._forever) {
      throw new Error("Caching has already been configured with .forever()");
    }
    this._never = true;
    this._configured = true;
  }

  using<T>(handler: (data: SideChannel) => T): T {
    if (!this._active) {

View on GitHub (pinned to 06b6eae39d)

Solutions

  1. Ensure only one cache mode is set per factory invocation; use a single api.cache(...) call guarded by early returns.
  2. Delete the stale .never() call left behind after switching to .forever().
  3. Prefer api.cache(() => condition) for environment-dependent caching instead of imperatively branching between never/forever.

Example fix

// before
module.exports = function (api) {
  api.cache.never();
  if (process.env.NODE_ENV === "production") api.cache.forever(); // throws
  return {};
};

// after
module.exports = function (api) {
  api.cache(() => process.env.NODE_ENV === "production");
  return {};
};
Defensive patterns

Strategy: validation

Validate before calling

module.exports = function (api) {
  // Set exactly one mode, guarded by early return
  if (process.env.NODE_ENV === "test") {
    api.cache.never();
    return { /* test config */ };
  }
  api.cache.forever();
  return { /* prod config */ };
};

Prevention

When it happens

Trigger: A plugin/preset factory calls api.cache.never() and then api.cache.forever() (or api.cache(false) followed by api.cache(true)) in the same invocation. Both branches execute because they are not guarded by an early return.

Common situations: Conditionally choosing cache mode with if/else where both calls accidentally execute; copy-pasting cache boilerplate and forgetting to delete the previous line; refactoring that leaves a stale cache call.

Related errors


AI-assisted analysis of babel/babel@06b6eae39d (2026-08-03). Data as JSON: /data/errors/243a3215f24f93d8.json. Report an issue: GitHub.