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
- Ensure only one cache mode is set per factory invocation; use a single api.cache(...) call guarded by early returns.
- Delete the stale .never() call left behind after switching to .forever().
- 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
- Use a single api.cache(...) call per factory invocation.
- Prefer the functional form api.cache(() => condition) over imperative never/forever.
- Lint your config for duplicate cache calls.
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
- Cannot change caching after evaluation has completed.
- Caching has already been configured with .forever()
- Caching has already been configured with .never or .forever(
- You appear to be using an async cache handler, which your cu
- Cache keys must be either string, boolean, number, null, or
AI-assisted analysis of babel/babel@06b6eae39d (2026-08-03).
Data as JSON: /data/errors/243a3215f24f93d8.json.
Report an issue: GitHub.