Skip to content

oxfmt: CSS files fail with TypeError: Cannot use 'in' operator to search for 'importer' in undefined when using parallel workers #20033

@AlexisWalravens

Description

@AlexisWalravens

Bug Report

I just updated to oxfmt: 0.36.0, and I sometimes had errors when linting css files, it did not happen everytime.
I asked claude to investigate, and here is what it found.

I though it might be worthy of a github issue, hope it helps 🙏

Summary

When running oxfmt --check (or --write) on a project containing CSS files, random CSS files fail with:

× TypeError: Cannot use 'in' operator to search for 'importer' in undefined
│ [path/to/some/file.css]

The crash is non-deterministic — different CSS files fail per run (and between local/CI environments), which strongly points to a race condition in the worker thread pool.

Workaround

Running with --threads=1 eliminates the crash entirely:

oxfmt --check ./ --threads=1  # passes on all 2286 files

Root Cause (analysis)

The CSS parser is registered in prettier-plugin-tailwindcss's createPlugin call inside dist/dist-BIcAktiQ.js:

// dist-BIcAktiQ.js (line 14904)
defineTransform({
  load: [postcss_exports],   // <-- postcss plugin reference
  parsers: { css: {}, scss: {}, less: {} },
  transform: transformCss
})

postcss_exports is imported from ./angular-BYaMjeNY.js, which itself imports from ./dist-BIcAktiQ.js — a circular ESM dependency:

dist-BIcAktiQ.js  →  angular-BYaMjeNY.js  →  dist-BIcAktiQ.js

In the main thread this resolves correctly via ESM live bindings. However, when worker threads (cli-worker.js) initialize their own module graph, the circular dependency causes postcss_exports to evaluate as undefined in some workers.

When loadPlugin(source) is then called with that undefined value:

// dist-BIcAktiQ.js (line 14204)
async function loadPlugin(source) {
  if ("importer" in source && ...)  // ← throws TypeError when source === undefined

The check "importer" in undefined throws the observed TypeError.

Steps to Reproduce

  1. Create a project with several CSS files
  2. Enable sortTailwindcss in .oxfmtrc.json (triggers the postcss plugin path)
  3. Run oxfmt --check ./ with default thread count
  4. Observe random CSS files failing with the TypeError
  5. Run again with --threads=1 — all files pass

Environment

oxfmt 0.36.0
OS macOS Darwin 25.3.0 arm64
Node v24.13.1
Bun 1.3.10

Expected Behavior

CSS files should format/check successfully regardless of the number of worker threads used.

Suggested Fix

Either:

  • Guard loadPlugin against undefined: if (source && "importer" in source ...)
  • Break the circular ESM dependency between dist-BIcAktiQ.js and angular-BYaMjeNY.js so postcss_exports is always defined in worker contexts

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions