{"record":{"id":"62521f8e9c772161","repo":"avajs/ava","slug":"chalk-has-already-been-configured","errorCode":null,"errorMessage":"Chalk has already been configured","messagePattern":"Chalk has already been configured","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/chalk.js","lineNumber":10,"sourceCode":"import {Chalk} from 'chalk'; // eslint-disable-line unicorn/import-style\n\nlet chalk = new Chalk(); // eslint-disable-line import-x/no-mutable-exports\n\nexport {chalk};\n\nlet configured = false;\nexport function set(options) {\n\tif (configured) {\n\t\tthrow new Error('Chalk has already been configured');\n\t}\n\n\tconfigured = true;\n\tchalk = new Chalk(options);\n}\n","sourceCodeStart":1,"sourceCodeEnd":16,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/chalk.js#L1-L16","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nchalk.set({level: 2});\ninitLogging(); // also calls chalk.set → throws\n// after\nif (!chalk.level) chalk.set({level: 2});\ninitLogging();","handlingStrategy":"validation","validationCode":"if (chalk.level === undefined) chalk.set({level: 2});","typeGuard":"const isChalkConfigured = () => chalk.level !== undefined;","tryCatchPattern":"try {\n  chalk.set(options);\n} catch (err) {\n  if (!/already been configured/.test(err.message)) throw err;\n  // chalk already set up; proceed with existing configuration\n}","preventionTips":["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."],"tags":["configuration","duplicate-initialization","chalk"],"backgroundTag":"already-configured","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}