paperclipai/paperclip · error · Error

usage: prepare-npm-readme.mjs

Error message

usage: prepare-npm-readme.mjs <source> <destination> <asset-ref>

What it means

When prepare-npm-readme.mjs is executed directly (process.argv[1] resolves to the module file), it expects exactly three CLI arguments: source README path, destination path, and the immutable asset ref. Missing any of them aborts with the usage line, since it cannot guess where to read, write, or which ref to pin.

Solutions

  1. Run with all three arguments: node scripts/prepare-npm-readme.mjs <source> <destination> <asset-ref>.
  2. If the ref comes from an env var or command substitution, echo it first to confirm it is non-empty before invoking.
  3. Quote each path argument in the shell so spaces or empty variables do not collapse positional arguments.

Example fix

// before (shell)
node scripts/prepare-npm-readme.mjs README.md dist/README.md $REF
// after
REF=$(git rev-parse HEAD); node scripts/prepare-npm-readme.mjs README.md dist/README.md "$REF"
Defensive patterns

Strategy: validation

Validate before calling

const [sourcePath, destinationPath, assetRef] = process.argv.slice(2);
if (!sourcePath || !destinationPath || !assetRef) {
  console.error('usage: prepare-npm-readme.mjs <source> <destination> <asset-ref>');
  process.exit(1);
}

Try / catch

try { main(); } catch (e) { if (e.message.startsWith('usage: prepare-npm-readme')) { console.error(e.message); process.exit(1); } throw e; }

Prevention

When it happens

Trigger: Running `node scripts/prepare-npm-readme.mjs` or with fewer than three space-separated arguments; quoting mistakes that collapse arguments (e.g. passing "README.md dist/" as one token); calling the script from a wrapper that drops the asset-ref argument.

Common situations: Copy-pasting the command from docs but omitting the ref; shell variable expansions resolving to empty strings (e.g. $COMMIT_SHA unset); CI steps edited to remove what looked like a redundant argument.

Understand the failure class

Background: "no subcommand specified" and "... is required": CLI errors when a required argument is missing — this error's family across 13 libraries.

Related errors


AI-assisted analysis of paperclipai/paperclip@3f1d897a7c (2026-09-18). Data as JSON: /api/errors/0d439c0041d07bfb. Report an issue: GitHub.

Appendix: source

Thrown at scripts/prepare-npm-readme.mjs:29

    `https://raw.githubusercontent.com/paperclipai/paperclip/${assetRef}/doc/assets/`;

  return readme.replace(
    /((?:src|srcset)=["'])([^"']*)(["'])/g,
    (_match, prefix, value, suffix) =>
      `${prefix}${value.replace(
        /(^|,\s*)doc\/assets\//g,
        `$1${assetBaseUrl}`,
      )}${suffix}`,
  );
}

const isDirectRun =
  process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);

if (isDirectRun) {
  const [sourcePath, destinationPath, assetRef] = process.argv.slice(2);
  if (!sourcePath || !destinationPath || !assetRef) {
    throw new Error(
      "usage: prepare-npm-readme.mjs <source> <destination> <asset-ref>",
    );
  }

  writeFileSync(
    destinationPath,
    prepareNpmReadme(readFileSync(sourcePath, "utf8"), assetRef),
  );
}

View on GitHub (pinned to 3f1d897a7c)