moeru-ai/airi · error

Worklet loading failed: ${err}

Error message

Worklet loading failed: ${err}

What it means

loadWorklets calls AudioContext.audioWorklet.addModule for two processor worklets (ProcessorWorkletURL and LibsamplerateWorkletURL). If either addModule rejects, the error is rethrown as 'Worklet loading failed'. Common Web Audio failure modes apply: insecure context (http instead of https/localhost), 404 on the worklet URL, CORS restriction, or the browser not supporting audioWorklet.

Source

Thrown at packages/audio/src/audio-context/index.ts:73

    catch (err) {
      console.error('AudioContext state listener error:', err)
    }
  })
}

async function loadWorklets() {
  if (!context || workletLoaded)
    return

  try {
    await context.audioWorklet.addModule(ProcessorWorkletURL)
    await context.audioWorklet.addModule(LibsamplerateWorkletURL)

    workletLoaded = true
  }
  catch (err) {
    console.error('Failed to load AudioWorklets:', err)
    throw new Error(`Worklet loading failed: ${err}`)
  }
}

export async function initializeAudioContext(requestedSampleRate: number = 48000): Promise<AudioContext> {
  // Use high quality base sample rate
  const baseSampleRate = Math.max(requestedSampleRate, 48000)

  if (context && isReady && sampleRate === baseSampleRate && workletLoaded) {
    return context
  }

  if (isInitializing) {
    return new Promise((resolve, reject) => {
      const checkReady = () => {
        if (!isInitializing) {
          if (context && isReady && workletLoaded) {
            resolve(context)
          }

View on GitHub (pinned to 27111382b4)

Solutions

  1. Verify ProcessorWorkletURL and LibsamplerateWorkletURL resolve with HTTP 200 in the served environment.
  2. Ensure the page runs in a secure context (https or localhost/127.0.0.1).
  3. Feature-detect context.audioWorklet before calling initializeAudioContext and degrade gracefully.
  4. Check the worklet module for syntax errors and confirm the build emits the files.

Example fix

// before
await context.audioWorklet.addModule(ProcessorWorkletURL)
await context.audioWorklet.addModule(LibsamplerateWorkletURL)

// after
if (typeof context.audioWorklet?.addModule !== 'function') {
  throw new Error('AudioWorklet is not supported in this context (use a secure context / modern browser)')
}
await context.audioWorklet.addModule(new URL(ProcessorWorkletURL, location.href).toString())
await context.audioWorklet.addModule(new URL(LibsamplerateWorkletURL, location.href).toString())
Defensive patterns

Strategy: validation

Validate before calling

function canUseAudioWorklet(): boolean {
  return typeof window !== 'undefined'
    && 'AudioContext' in window
    && typeof window.AudioContext?.prototype?.audioWorklet?.addModule === 'function'
    && (window.isSecureContext ?? location.protocol.startsWith('https') || location.hostname === 'localhost')
}

Type guard

function supportsAudioWorklet(ctx: AudioContext | null | undefined): ctx is AudioContext {
  return !!ctx && typeof (ctx as any).audioWorklet?.addModule === 'function'
}

Try / catch

try {
  await loadWorklets()
}
catch (err) {
  // degrade to a non-worklet audio path instead of crashing
  console.warn('AudioWorklet unavailable; falling back', err)
}

Prevention

When it happens

Trigger: The worklet module URL 404s because the bundler did not emit it; the page is served over plain http on a non-localhost host so AudioWorklet is disabled; CORS blocks the cross-origin worklet script; an older browser/engine lacks audioWorklet support; a syntax error inside the worklet module causes addModule to reject.

Common situations: Dev server misconfigured to serve the worklet at the wrong path; production deploy over http; Safari/older WebView without audioWorklet; worklet file excluded from the build output.

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/96cd9d205bfd43c4. Report an issue: GitHub.