moeru-ai/airi · warning

[OPFS] ZipLoader not found in middlewares, caching disabled

Error message

[OPFS] ZipLoader not found in middlewares, caching disabled

What it means

live2d-opfs-registration inserts OPFSCache.checkMiddleware before ZipLoader.factory and OPFSCache.saveMiddleware after it in Live2DFactory.live2DModelMiddlewares, so models loaded from zips get cached in OPFS. ZipLoader.factory is the anchor; if it is not present in the middleware array, there is nothing to splice around and OPFS caching is silently disabled with this warning.

Source

Thrown at packages/stage-ui-live2d/src/utils/live2d-opfs-registration.ts:17

import { Live2DFactory, ZipLoader } from 'pixi-live2d-display/cubism4'

import { OPFSCache } from './opfs-loader'

const zipLoaderIndex = Live2DFactory.live2DModelMiddlewares.indexOf(ZipLoader.factory)

if (Live2DFactory.live2DModelMiddlewares.includes(OPFSCache.checkMiddleware)) {
  // Middlewares already registered.
}
else if (zipLoaderIndex !== -1) {
  // Insert Check before ZipLoader
  Live2DFactory.live2DModelMiddlewares.splice(zipLoaderIndex, 0, OPFSCache.checkMiddleware)
  // Insert Save after ZipLoader
  Live2DFactory.live2DModelMiddlewares.splice(zipLoaderIndex + 2, 0, OPFSCache.saveMiddleware)
}
else {
  console.warn('[OPFS] ZipLoader not found in middlewares, caching disabled')
}

View on GitHub (pinned to 677329427f)

Solutions

  1. Ensure the ZipLoader-enabled cubism4 entry ('pixi-live2d-display/cubism4') is imported (and its ZipLoader registered) before importing the OPFS registration module
  2. Assert at registration time that Live2DFactory.live2DModelMiddlewares includes ZipLoader.factory, and fail loudly in dev if not
  3. Avoid replacing the middleware array wholesale; mutate in place so the anchor stays

Example fix

// before
import { Live2DFactory, ZipLoader } from 'pixi-live2d-display/cubism4'
const idx = Live2DFactory.live2DModelMiddlewares.indexOf(ZipLoader.factory)
if (idx === -1)
  console.warn('[OPFS] ZipLoader not found, caching disabled')

// after (make the missing anchor a dev-time failure, or register it first)
import { Live2DFactory, ZipLoader } from 'pixi-live2d-display/cubism4'
let idx = Live2DFactory.live2DModelMiddlewares.indexOf(ZipLoader.factory)
if (idx === -1) {
  Live2DFactory.live2DModelMiddlewares.push(ZipLoader.factory)
  idx = Live2DFactory.live2DModelMiddlewares.length - 1
}
Defensive patterns

Strategy: validation

Validate before calling

import { Live2DFactory, ZipLoader } from 'pixi-live2d-display/cubism4'

const hasZipLoader = Live2DFactory.live2DModelMiddlewares.includes(ZipLoader.factory)
if (!hasZipLoader) {
  // register the anchor first, or skip OPFS registration knowingly
  Live2DFactory.live2DModelMiddlewares.push(ZipLoader.factory)
}

Type guard

function hasZipLoaderMiddleware(middlewares: Array<unknown>): boolean {
  return middlewares.includes(ZipLoader.factory)
}

Prevention

When it happens

Trigger: The pixi-live2d-display bundle variant loaded does not register ZipLoader (a build stripping the zip loader), or code that cleared/replaced Live2DFactory.live2DModelMiddlewares before this module evaluated.

Common situations: Tree-shaking or a custom cubism4 entry that omits ZipLoader; middleware arrays mutated by another integration; import-order changes after refactoring.

Related errors


AI-assisted analysis of moeru-ai/airi@677329427f (2026-08-18). Data as JSON: /api/errors/00d9f237f0210609. Report an issue: GitHub.