danny-avila/LibreChat · error · Error

Invalid LibreChat file format

Error message

Invalid LibreChat file format

What it means

Thrown by importLibreChatConvo (utils/import/importers.js) when, after the conversationId check passed, none of the message-source branches apply — jsonData.recursive is false and messagesToImport is falsy. The file looked like a LibreChat export (it had conversationId) but its messages/messagesTree resolved to an empty or undefined payload, so there is nothing to clone.

Source

Thrown at api/server/utils/import/importers.js:296

          if (message.children && message.children.length > 0) {
            flattenMessages(message.children, message.messageId, flatMessages);
          }
        }
        return flatMessages;
      };

      const flatMessages = flattenMessages(messagesToImport);
      cloneMessagesWithTimestamps(flatMessages, importBatchBuilder);
    } else if (messagesToImport) {
      cloneMessagesWithTimestamps(messagesToImport, importBatchBuilder);
      for (const message of messagesToImport) {
        if (!firstMessageDate && message.createdAt) {
          firstMessageDate = new Date(message.createdAt);
        }
      }
    } else {
      throw new Error('Invalid LibreChat file format');
    }

    if (firstMessageDate === 'Invalid Date') {
      firstMessageDate = null;
    }

    importBatchBuilder.finishConversation(
      jsonData.title,
      firstMessageDate ?? new Date(),
      options,
      defaultModel,
    );
    await importBatchBuilder.saveBatch();
    logger.debug(`user: ${requestUserId} | Conversation "${jsonData.title}" imported`);
  } catch (error) {
    logger.error(`user: ${requestUserId} | Error creating conversation from LibreChat file`, error);
    throw error;
  }

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Open the file and confirm jsonData.messages (or jsonData.messagesTree) is a non-empty array of message objects with text or content.
  2. Re-export the conversation ensuring it contains at least one message.
  3. If the export legitimately has zero messages, skip the import rather than submitting the file.

Example fix

// before: file has conversationId but empty messages
// after: ensure messages payload is populated
if (!jsonData.messages?.length && !jsonData.messagesTree?.length) {
  throw new Error('Nothing to import: export contains no messages');
}
Defensive patterns

Strategy: validation

Validate before calling

const messagesToImport = jsonData.messagesTree || jsonData.messages;
if (!messagesToImport || (Array.isArray(messagesToImport) && messagesToImport.length === 0)) {
  throw new Error('Invalid LibreChat file format');
}

Type guard

const hasImportableMessages = (j) => {
  const m = j?.messagesTree ?? j?.messages;
  return Array.isArray(m) && m.length > 0;
};

Try / catch

try {
  await importer(jsonData, requestUserId, builderFactory, userRole);
} catch (err) {
  if (err.message === 'Invalid LibreChat file format') {
    return res.status(400).json({ message: 'Export contains no importable messages.' });
  }
  throw err;
}

Prevention

When it happens

Trigger: A LibreChat export where messagesTree and messages are both empty arrays or undefined; messagesTree present but every node filtered out (no text/content); an export truncated so the messages section is missing.

Common situations: Exporting an empty conversation; hand-editing the export and dropping the messages array; schema drift between export and import versions of LibreChat.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/f21045cd51ccc0a1. Report an issue: GitHub.