phaserjs/phaser · error · Error

No cached audio asset with key "

Error message

No cached audio asset with key "

What it means

Thrown by HTML5AudioSound constructor when manager.game.cache.audio.get(key) returns a falsy value, meaning no audio asset was loaded under that key. The HTML5 Audio sound backend requires the asset to be in the audio cache before a Sound instance is created from it. Note the error message text has an unclosed quote (a known cosmetic bug) but the cause is purely a cache miss.

Source

Thrown at src/sound/html5/HTML5AudioSound.js:63

    function HTML5AudioSound (manager, key, config)
    {
        if (config === undefined) { config = {}; }

        /**
         * An array containing all HTML5 Audio tags that could be used for individual
         * sound playback. Number of instances depends on the config value passed
         * to the `Loader#audio` method call, default is 1.
         *
         * @name Phaser.Sound.HTML5AudioSound#tags
         * @type {HTMLAudioElement[]}
         * @since 3.0.0
         */
        this.tags = manager.game.cache.audio.get(key);

        if (!this.tags)
        {
            throw new Error('No cached audio asset with key "' + key);
        }

        /**
         * Reference to an HTML5 Audio tag used for playing sound.
         *
         * @name Phaser.Sound.HTML5AudioSound#audio
         * @type {HTMLAudioElement}
         * @default null
         * @since 3.0.0
         */
        this.audio = null;

        /**
         * Timestamp as generated by the Request Animation Frame or SetTimeout
         * representing the time at which the delayed sound playback should start.
         * Set to 0 if sound playback is not delayed.
         *
         * @name Phaser.Sound.HTML5AudioSound#startTime

View on GitHub (pinned to 41be1e462b)

Solutions

  1. Preload the audio with this.load.audio(key, url) and use the same key.
  2. Move sound.add calls into create() or a loader complete callback so the cache is populated.
  3. Verify with this.game.cache.audio.has(key) before constructing the sound.
  4. Check the Network panel for failed audio requests during preload.

Example fix

// before
// in preload: (forgot to load)
const s = this.sound.add('beep'); // throws

// after
preload() { this.load.audio('beep', 'audio/beep.mp3'); }
create() { const s = this.sound.add('beep'); }
Defensive patterns

Strategy: validation

Validate before calling

function addHtml5Sound(manager, key) {
  if (!manager.game.cache.audio.has(key)) {
    throw new Error(`Audio '${key}' not in cache; call this.load.audio first`);
  }
  return new Phaser.Sound.HTML5AudioSound(manager, key);
}

Type guard

function audioCached(game, key) { return game.cache.audio.has(key); }

Prevention

When it happens

Trigger: Constructing new Phaser.Sound.HTML5AudioSound(manager, key) for a key never loaded; misspelling the key vs. the loader key; loading under a different cache bucket; calling sound.add before the loader has finished.

Common situations: Forgetting this.load.audio('key', url) before sound.add('key'); using the wrong key casing; the load failed (404 / decode error) so the cache entry is absent; audio disabled in config so nothing was cached; calling from preload() instead of create().

Related errors


AI-assisted analysis of phaserjs/phaser@41be1e462b (2026-08-13). Data as JSON: /api/errors/442678a234173fef. Report an issue: GitHub.