avajs/ava · error · Error
Chalk has already been configured
Error message
Chalk has already been configured
What it means
Chalk's module-level `set()` function applies global options (like color level) by re-creating the chalk instance, but this can only happen once per process. If `set()` is called a second time, the library throws to prevent silently overwriting an already-configured chalk instance shared by all consumers.
Source
Thrown at lib/chalk.js:10
import {Chalk} from 'chalk'; // eslint-disable-line unicorn/import-style
let chalk = new Chalk(); // eslint-disable-line import-x/no-mutable-exports
export {chalk};
let configured = false;
export function set(options) {
if (configured) {
throw new Error('Chalk has already been configured');
}
configured = true;
chalk = new Chalk(options);
}
View on GitHub (pinned to bbfd946322)
Solutions
- Remove or guard the duplicate set() call — configure chalk exactly once at process start.
- Track configuration with your own flag and skip the second call if already configured.
- If options must change, construct a new Chalk instance (`new Chalk(options)`) instead of calling set().
- Isolate configurations by moving one consumer into a separate process/worker.
Example fix
// before
chalk.set({level: 2});
initLogging(); // also calls chalk.set → throws
// after
if (!chalk.level) chalk.set({level: 2});
initLogging(); Defensive patterns
Strategy: validation
Validate before calling
if (chalk.level === undefined) chalk.set({level: 2}); Type guard
const isChalkConfigured = () => chalk.level !== undefined;
Try / catch
try {
chalk.set(options);
} catch (err) {
if (!/already been configured/.test(err.message)) throw err;
// chalk already set up; proceed with existing configuration
} Prevention
- Configure chalk in exactly one bootstrap module.
- Guard set() with a module-level `configured` flag of your own.
- Use `new Chalk(options)` for per-consumer options instead of global set().
- Avoid calling set() from library code that consumers also use.
When it happens
Trigger: Calling `chalk.set(options)` (or an API that wraps it, e.g. chalk.level configuration via set) more than once in the same process — e.g. once in app bootstrap and again in a library, a worker, or on a config reload.
Common situations: Application code and a dependency both configure chalk; hot-reloading a module that calls set() at import time; multiple entry points (CLI + tests) each calling set(); accidentally importing the configure side-effect twice via bundlers.
Related errors
- The ’environmentVariables’ configuration must be an object c
- The extensions option must be an array
- Unexpected duplicate extensions in options: ’${[...duplicate
- The ’files’ configuration must be an array containing glob p
- The ’watchMode.ignoreChanges’ configuration must be an array
AI-assisted analysis of avajs/ava@bbfd946322 (2026-09-02).
Data as JSON: /api/errors/62521f8e9c772161.
Report an issue: GitHub.