jackwener/OpenCLI · error · ArgumentError

Image file not found: ${absPath}

Error message

Image file not found: ${absPath}

What it means

ArgumentError from validateImagePaths in the publish CLI: path.resolve was applied to the given file path and fs.existsSync found no file at the resolved absolute location. The publish flow aborts before opening the browser because there is nothing to upload.

Source

Thrown at clis/xiaohongshu/publish.js:129

    if (
        value
        && typeof value === 'object'
        && typeof value.session === 'string'
        && Object.prototype.hasOwnProperty.call(value, 'data')
    ) {
        return value.data;
    }
    return value;
}
/**
 * Validate image paths: check existence and extension.
 * Returns resolved absolute paths.
 */
function validateImagePaths(filePaths) {
    return filePaths.map((filePath) => {
        const absPath = path.resolve(filePath);
        if (!fs.existsSync(absPath))
            throw new ArgumentError(`Image file not found: ${absPath}`);
        const ext = path.extname(absPath).toLowerCase();
        if (!SUPPORTED_EXTENSIONS[ext]) {
            throw new ArgumentError(`Unsupported image format "${ext}". Supported: jpg, png, gif, webp`);
        }
        return absPath;
    });
}
/** CSS selector for image-accepting file inputs. */
const IMAGE_INPUT_SELECTOR = 'input[type="file"][accept*="image"],'
    + 'input[type="file"][accept*=".jpg"],'
    + 'input[type="file"][accept*=".jpeg"],'
    + 'input[type="file"][accept*=".png"],'
    + 'input[type="file"][accept*=".gif"],'
    + 'input[type="file"][accept*=".webp"]';
/**
 * Upload images via CDP DOM.setFileInputFiles — Chrome reads files directly
 * from the local filesystem, avoiding base64 payload size limits.
 *

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check the exact path exists: ls the resolved absolute path printed in the error message.
  2. Expand '~' and environment variables in the path or pass an absolute path.
  3. Run the command from the directory you expect, or fix the relative path.
  4. Verify the file was not moved/deleted before publish.

Example fix

// before
await xhs.publish({ images: ['~/Pictures/note.png'] });
// after
const os = require('os');
const p = '~/Pictures/note.png'.replace(/^~/, os.homedir());
if (!require('fs').existsSync(p)) throw new Error('missing image: ' + p);
await xhs.publish({ images: [p] });
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs'), path = require('path');
const abs = images.map(p => path.resolve(p.replace(/^~/, require('os').homedir())));
const missing = abs.filter(p => !fs.existsSync(p));
if (missing.length) throw new Error('Missing image files: ' + missing.join(', '));

Type guard

function imageFileExists(p) {
  return typeof p === 'string' && p.length > 0 && fs.existsSync(path.resolve(p));
}

Try / catch

try {
  await xhs.publish({ images });
} catch (err) {
  if (err.message.startsWith('Image file not found:')) {
    console.error('Fix path:', err.message);
  } else throw err;
}

Prevention

When it happens

Trigger: Passing a non-existent or misspelled image path to the publish command's image arguments; running from a different working directory than assumed so a relative path resolves elsewhere; file deleted between planning and publishing.

Common situations: Typos in path or extension; relative paths like './img.png' when cwd differs; paths with unexpanded '~' or shell variables; case-sensitive filesystems where the filename casing is wrong.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/faec220b0a711b02. Report an issue: GitHub.