Skip to content

CLI Fails on Mobile Emulators with "invalid zstd data" Error #60

@LarryJunior21

Description

@LarryJunior21

The Raisely CLI local development server crashes when accessed from mobile emulators (iOS Simulator, Android Emulator) with the error Error: invalid zstd data. The same CLI works perfectly in desktop browsers and with Angular CLI on the same emulators.

Error Details

Error: invalid zstd data
    at rzfh (file:///.../@raisely/cli/node_modules/fzstd/esm/index.mjs:122:5)
    at Decompress.push (file:///.../@raisely/cli/node_modules/fzstd/esm/index.mjs:699:34)
    at response (file:///.../@raisely/cli/src/local.js:155:25)

Environment

  • Node.js: v20.19.0
  • Raisely CLI: Latest version
  • Tested on: iOS Simulator (macOS), Android Emulator (Android Studio)
  • Works on: Desktop browsers (Chrome, Safari, Firefox)

In src/local.js lines 144-155, the responseInterceptor assumes ALL proxied responses are zstd-compressed and attempts to decompress them using fzstd.Decompress(). However, many responses (especially from mobile user agents) are not zstd-compressed, causing the decompression to fail.

The code does not check the content-encoding header before attempting decompression.

This works for me as a local fix

Replace the response handling code in src/local.js (lines 144-155) with:

onProxyRes: responseInterceptor(
    async (responseBuffer, proxyRes, req, res) => {
        const contentEncoding = proxyRes.headers['content-encoding'];
        
        let response;
        
        if (contentEncoding === 'zstd') {
            try {
                response = await new Promise((resolve, reject) => {
                    const decompressedChunks = [];
                    const decompressStream = new fzstd.Decompress((chunk, isLast) => {
                        decompressedChunks.push(chunk);
                        if (isLast) {
                            resolve(Buffer.concat(decompressedChunks).toString('utf8'));
                        }
                    });
                    try {
                        decompressStream.push(responseBuffer);
                        decompressStream.push(new Uint8Array(0), true);
                    } catch (error) {
                        reject(error);
                    }
                });
            } catch (error) {
                console.warn('Failed to decompress zstd response, treating as uncompressed:', error.message);
                response = responseBuffer.toString('utf8');
            }
        } else {
            response = responseBuffer.toString('utf8');
        }
        
        return response
            .replace(/* existing replacements */)

This bug prevents mobile development testing, which is critical for responsive web development.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions