# Troubleshooting

## `TypeError: mod.createXronox is not a function` (during `XronoxStore.init`)

**Cause:** Integration tests (or code) loaded **`@x12i/xronox-store`’s CJS build**, which `require()`s `@x12i/xronox`. Newer xronox **CJS** entry is a **Proxy**; `createXronox` may not be a function until ESM finishes loading, so the store’s synchronous `mod.createXronox()` fails.

**Fix:** Run tests as **ESM** against **`dist/index.js`** (this package’s default: `.tests-out/` + `{ "type": "module" }`, `import '../dist/index.js'`). Do not point integration tests at **`dist-cjs`** unless xronox-store/xronox fix the CJS interop.

---

## `npm warn Unknown env config "-authtoken"`

**Cause:** Invalid auth line in `.npmrc` (often missing `//` before the host).

**Fix:** Use `//registry.npmjs.org/:_authToken=...` — see [github-packages.md](./github-packages.md).

---

## `TypeError: mod.createXronox is not a function` (during `XronoxStore` init)

**Cause:** Usually a **version skew** between `@x12i/xronox-store` and how it loads `@x12i/xronox`, or a broken/partial install (wrong auth, cached tarball).

**What to try:**

1. Delete `node_modules` and lockfile, reinstall with a correct `.npmrc`.
2. Pin `@x12i/xronox-store` and `@x12i/xronox` to versions known to work together (check xronox-store release notes).
3. Confirm `mongoUri` / `mongoRole` / `xronox` options match what xronox-store expects for your environment. (DB name is env-driven: `ACTIVIX_DB_NAME` -> `MONGO_AI_LOGS_DB` -> `MONGO_LOGS_DB` -> `MONGO_DB` -> `activitix`.)

---

## `404` on `@x12i/xronox-store` during `npm install`

**Cause:** Package is private and your npm token doesn’t have access (npm often returns 404 for unauthorized private packages).

**Fix:** [github-packages.md](./github-packages.md)

---

## `patchRecord` / xronox-store error message

`patchRecord` treats a missing document by matching **`no document for key`** in the error text from `@x12i/xronox-store` `patchByKey`. If that string changes in a future store release, update **`Activix.ts`** and the spy tests accordingly.

---

## TypeScript `TS2352` casting generic `T`

**Cause:** Strict rules on `as T` from a widened object (e.g. adding fixed `error` field).

**Fix:** Use `as unknown as T` where the runtime shape is intentional (see `failRecord` in `Activix.ts`).

---

## Tests skip or exit 0 with “set MONGO_URI…”

**Cause:** No `.env` or missing variables.

**Fix:** Copy `.env.example` → `.env` and set `MONGO_URI`. Database name defaults to `activitix`; set `ACTIVIX_DB_NAME` when you need a different database.
