babel/babel · error

Caching has already been configured with .forever()

Error message

Caching has already been configured with .forever()

What it means

Thrown by CacheConfigurator.never() when this._forever is already true. The mirror of error [4]: having already committed to forever caching, switching to never is forbidden because the forever entry is already immutable and would never be invalidated. Cache modes are set once.

Source

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

  }

  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) {
      throw new Error("Cannot change caching after evaluation has completed.");
    }
    if (this._never || this._forever) {
      throw new Error(
        "Caching has already been configured with .never or .forever()",
      );
    }
    this._configured = true;

    const key = handler(this._data);

View on GitHub (pinned to 06b6eae39d)

Solutions

  1. Keep a single cache-mode call per factory invocation.
  2. Delete the leftover .forever() call when switching to .never() (though .never() is discouraged).
  3. Use api.cache(() => value) for conditional caching instead of imperatively flipping modes.

Example fix

// before
module.exports = function (api) {
  api.cache.forever();
  if (shouldInvalidate) api.cache.never(); // throws
  return {};
};

// after
module.exports = function (api) {
  api.cache(() => !shouldInvalidate);
  return {};
};
Defensive patterns

Strategy: validation

Validate before calling

module.exports = function (api) {
  // Only one unconditional mode per invocation
  api.cache.never();
  // do NOT also call api.cache.forever() here
  return { visitor: {} };
};

Prevention

When it happens

Trigger: A factory calls api.cache.forever() (or api.cache(true)) and then api.cache.never() in the same invocation — both execute due to missing early return.

Common situations: Refactoring cache logic and leaving both calls; copy-paste of cache boilerplate; conditional branches where both paths run.

Related errors


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