ruvnet/ruflo · error · Error
Invalid JSON in import file: ${resolved}
Error message
Invalid JSON in import file: ${resolved} What it means
ConfigFileManager.importFrom reads the import file, then JSON.parse is attempted inside a try/catch; if parsing throws, the file exists but is not valid JSON. This is a content-validity error distinct from the missing-file error.
Source
Thrown at v3/@claude-flow/cli/src/services/config-file-manager.ts:161
/** Export config to a specific path */
exportTo(cwd: string, exportPath: string): void {
const config = this.getConfig(cwd);
const resolved = path.resolve(cwd, exportPath);
this.writeAtomic(resolved, config);
}
/** Import config from a specific path */
importFrom(cwd: string, importPath: string): void {
const resolved = path.resolve(cwd, importPath);
if (!fs.existsSync(resolved)) {
throw new Error(`Import file not found: ${resolved}`);
}
const content = fs.readFileSync(resolved, 'utf-8');
let imported: Record<string, unknown>;
try {
imported = JSON.parse(content);
} catch {
throw new Error(`Invalid JSON in import file: ${resolved}`);
}
if (typeof imported !== 'object' || imported === null || Array.isArray(imported)) {
throw new Error('Import file must contain a JSON object');
}
const targetPath = this.configPath ?? path.resolve(cwd, CONFIG_FILENAMES[0]);
this.writeAtomic(targetPath, imported);
this.config = imported;
this.configPath = targetPath;
}
/** Get the path to the current config file */
getConfigPath(): string | null {
return this.configPath;
}
/** Get default config */
getDefaults(): Record<string, unknown> {
return { ...DEFAULT_CONFIG };View on GitHub (pinned to 6b01dc5a68)
Solutions
- Validate the file with a JSON linter or JSON.parse(fs.readFileSync(p,'utf-8')) before calling importFrom.
- Strip JSONC comments / trailing commas from the source, or convert it to strict JSON.
- Re-export a known-good config from another project and import that.
- Ensure the file is UTF-8 without BOM.
Example fix
// before
manager.importFrom(cwd, './config.json'); // throws 'Invalid JSON'
// after — pre-validate and surface a clearer error
const raw = fs.readFileSync(path.resolve(cwd, './config.json'), 'utf-8');
let parsed: unknown;
try { parsed = JSON.parse(raw); }
catch (e) { throw new Error(`config.json is not valid JSON: ${(e as Error).message}`); }
manager.importFrom(cwd, './config.json'); Defensive patterns
Strategy: validation
Validate before calling
const resolved = path.resolve(cwd, importPath); const raw = fs.readFileSync(resolved, 'utf-8'); JSON.parse(raw); // throws here with a clearer context if invalid manager.importFrom(cwd, importPath);
Try / catch
try {
manager.importFrom(cwd, importPath);
} catch (e) {
if ((e as Error).message.startsWith('Invalid JSON')) {
// surface file path + offer to re-export a known-good config
} else throw e;
} Prevention
- Validate import files with a JSON linter before importing.
- Keep config files strict JSON (no comments, no trailing commas).
- Write configs via exportTo/atomic writes rather than hand-editing.
- Ensure UTF-8 encoding without BOM.
When it happens
Trigger: The resolved import file contains malformed JSON: trailing commas, unquoted keys, single-quoted strings, a BOM/encoding issue, a partially written file, or JSON5/JSONC syntax that JSON.parse rejects.
Common situations: Importing a hand-edited file with comments (JSONC) or trailing commas; a previous atomic write was interrupted leaving truncated JSON; the file is actually YAML/TOML mislabeled .json; encoding is UTF-16 with BOM.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Import file must contain a JSON object
- Routes config must be a flat array of routes
- browser/eval: script exceeds maximum length of ${MAX_EVAL_SC
- Config file already exists: ${targetPath}. Use --force to ov
- Import file not found: ${resolved}
AI-assisted analysis of ruvnet/ruflo@6b01dc5a68 (2026-08-12).
Data as JSON: /api/errors/2057aaa9b21aa222.
Report an issue: GitHub.