culori icon indicating copy to clipboard operation
culori copied to clipboard

culori library requires explicit initialization call when used with ES modules

Open DFSIdigital opened this issue 7 months ago • 1 comments

Issue

When using culori with ES modules (type: "module" in package.json), the library requires an explicit initialization call to one of its color functions (e.g., rgb()) before other functions work correctly. This initialization requirement is not documented anywhere, leading to confusion and unexpected behavior.

Steps to Reproduce

  1. Create a project with type: "module" in package.json
  2. Install culori: npm install culori
  3. Import culori: import * as culori from 'culori'
  4. Try to use any of culori's functions without first calling culori.rgb() or another color parser
  5. Observe that color conversions may not work correctly

Expected Behavior

The library should work correctly after importing without requiring an explicit initialization call, or this requirement should be clearly documented.

Actual Behavior

Without first calling a function like culori.rgb('tomato'), other color functions may not work correctly because the color spaces aren't properly registered. This forces developers to add seemingly random code like:

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const tomato = culori.rgb('tomato');

This creates linting issues (unused variables) and confusion about why this line is necessary.

Environment

  • culori version: 4.0.1
  • TypeScript: ^5
  • Next.js: 15.2.3
  • React: ^19.0.0
  • Node.js: (latest LTS)
  • Package type: "module"

Workarounds

Currently using:

void culori.rgb('tomato'); // Initialize library with side effect

Proposed Solutions

  1. Document this initialization requirement in the README or API docs
  2. Provide an explicit initialization function like culori.initialize()
  3. Modify the library to automatically initialize when imported in ES modules

This issue affects developer experience and creates confusion, especially since the behavior is undocumented.

DFSIdigital avatar Mar 21 '25 12:03 DFSIdigital