Egonex-AI/Understand-Anything · error · Error
Invalid input: must contain projectRoot and files array
Error message
Invalid input: must contain projectRoot and files array
What it means
Thrown by extract-import-map.mjs main() after parsing its input JSON. It requires projectRoot (truthy) and files (an Array); batchImportData is optional. Failing this aborts before the graceful tree-sitter init block, because there is nothing to scan without a file list.
Source
Thrown at understand-anything-plugin/skills/understand/extract-import-map.mjs:1812
return [];
}
// ---------------------------------------------------------------------------
// Main
// ---------------------------------------------------------------------------
async function main() {
const [,, inputPath, outputPath] = process.argv;
if (!inputPath || !outputPath) {
process.stderr.write('Usage: node extract-import-map.mjs <input.json> <output.json>\n');
process.exit(1);
}
const inputRaw = readFileSync(inputPath, 'utf-8');
const input = JSON.parse(inputRaw);
const { projectRoot, files } = input;
if (!projectRoot || !Array.isArray(files)) {
throw new Error('Invalid input: must contain projectRoot and files array');
}
// Create tree-sitter plugin with all configs that have WASM grammars.
//
// WHY graceful init: the most likely real-world failure mode is the WASM
// loader failing to locate or fetch the grammar binaries (cache eviction,
// restricted sandboxes, transient FS issues). When that happens, we still
// want the script to complete — producing an empty importMap for every
// code file — rather than crashing the whole project-scanner pipeline.
// The structural graph will lose import edges, but all OTHER analysis
// (file inventory, exports inferred from filenames, etc.) keeps working.
let registry = null;
let treeSitterReady = false;
try {
const tsConfigs = builtinLanguageConfigs.filter(c => c.treeSitter);
const tsPlugin = new TreeSitterPlugin(tsConfigs);
await tsPlugin.init();
registry = new PluginRegistry();View on GitHub (pinned to 32944829e7)
Solutions
- Open the input JSON at the inputPath argument and confirm { projectRoot: <string>, files: [<string>, ...] }.
- If the producer used sourceFilePaths, rename it to files for this worker (or update the producer to emit both / the correct name).
- Ensure projectRoot is a non-empty string and files is an actual array (not a string, not an object).
- Re-run the upstream stage that emits import-input.json so it matches the current worker schema.
Example fix
// before — mismatched field name
{ "projectRoot": "./repo", "sourceFilePaths": ["./a.ts"] }
// after — this worker expects `files`
{ "projectRoot": "./repo", "files": ["./a.ts"] } Defensive patterns
Strategy: validation
Validate before calling
import { readFileSync } from 'node:fs';
function readImportMapInput(inputPath) {
const raw = JSON.parse(readFileSync(inputPath, 'utf-8'));
if (!raw.projectRoot) throw new Error('input missing projectRoot');
if (!Array.isArray(raw.files)) throw new Error('files must be an array');
return raw;
} Type guard
function isImportMapInput(v) {
return v !== null && typeof v === 'object'
&& typeof v.projectRoot === 'string' && v.projectRoot.length > 0
&& Array.isArray(v.files)
&& v.files.every((f) => typeof f === 'string');
} Try / catch
try {
const input = readImportMapInput(inputPath);
} catch (e) {
process.stderr.write(`extract-import-map input invalid: ${e.message}\n`);
process.exit(1);
} Prevention
- This worker expects `files` (not sourceFilePaths, not batchFiles) — match the exact field name.
- Producers should write the input via the same version of the worker that consumes it.
- Validate projectRoot is a non-empty string and files is an array before invoking.
When it happens
Trigger: process.argv lacks inputPath/outputPath (caught by the earlier usage exit). This throw fires when the parsed input JSON has no projectRoot or files is not an array — e.g. the field was named fileNames, the input was an empty object, or files was passed as a comma-separated string.
Common situations: The project-scanner / benchmark driver wrote the input with a different field name (files vs sourceFilePaths — note the sibling script uses sourceFilePaths; this one uses files). Truncated/empty input JSON. A producer that omits projectRoot when cwd is implied. Version drift between the producer and this worker's schema.
Related errors
- Invalid input: requires { projectRoot: string, sourceFilePat
- Invalid input: must contain projectRoot and batchFiles array
- output file missing after write: ${outputPath}
- Could not parse a Figma file key from: ${urlOrKey}
- ${flag} requires a value
AI-assisted analysis of Egonex-AI/Understand-Anything@32944829e7 (2026-08-12).
Data as JSON: /api/errors/b982e590ef1bf983.
Report an issue: GitHub.