{"record":{"id":"e29db2c372ebeb7d","repo":"actualbudget/actual","slug":"could-not-find-account-for-transaction-when-import","errorCode":null,"errorMessage":"Could not find account for transaction when importing","messagePattern":"Could not find account for transaction when importing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/loot-core/src/server/importers/ynab4.ts","lineNumber":158,"sourceCode":"  const accounts = await send('api/accounts-get');\n  const payees = await send('api/payees-get');\n\n  function getCategory(id: string) {\n    if (id == null || id === 'Category/__Split__') {\n      return null;\n    } else if (\n      id === 'Category/__ImmediateIncome__' ||\n      id === 'Category/__DeferredIncome__'\n    ) {\n      return incomeCategoryId;\n    }\n    return entityIdMap.get(id);\n  }\n\n  function isOffBudget(acctId: string) {\n    const acct = accounts.find(acct => acct.id === acctId);\n    if (!acct) {\n      throw new Error('Could not find account for transaction when importing');\n    }\n    return acct.offbudget;\n  }\n\n  // Go ahead and generate ids for all of the transactions so we can\n  // reliably resolve transfers\n  for (const transaction of data.transactions) {\n    entityIdMap.set(transaction.entityId, uuidv4());\n\n    if (transaction.subTransactions) {\n      for (const subTransaction of transaction.subTransactions) {\n        entityIdMap.set(subTransaction.entityId, uuidv4());\n      }\n    }\n  }\n\n  const transactionsGrouped = groupBy(data.transactions, 'accountId');\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/loot-core/src/server/importers/ynab4.ts#L140-L176","documentation":"During YNAB4 (importFromYNAB4) import, isOffBudget(acctId) looks up the account in the in-memory accounts list built from the parsed YNAB budget. If the account id referenced by a transaction is not present in that list, it throws this error. This indicates the YNAB4 export data is internally inconsistent — a transaction references an account that was never registered in the accounts array.","triggerScenarios":"Importing a YNAB4 .yfull/budget whose transaction references an accountId absent from the accounts in the parsed data; calling isOffBudget (via newTransaction) with a corrupted or truncated accountId; the accounts list was built from accounts.yfull while transactions come from a different/incompatible dataset.","commonSituations":"Corrupted or partially-copied YNAB4 budget directories (missing or mismatched Account.yfull vs Transaction files); hand-edited YNAB data; importing a budget from a different YNAB version where id formats differ.","solutions":["Re-export/re-copy the complete YNAB4 budget folder and retry the import, ensuring all data files come from the same budget.","Inspect the YNAB data for transactions whose accountId has no matching account and delete or fix them before import.","Catch the error to identify the offending accountId and patch the source data (add the missing account or remap the id) before re-importing.","If ids were remapped by a script, ensure the same entityIdMap is used for both accounts and transactions."],"exampleFix":"// before\nconst offbudget = isOffBudget(t.accountId); // throws if account missing\n// after\nconst account = accounts.find(a => a.id === t.accountId);\nif (!account) {\n  console.warn(`Skipping transaction ${t.id}: unknown account ${t.accountId}`);\n  continue;\n}\nconst offbudget = account.offbudget;","handlingStrategy":"validation","validationCode":"const account = accounts.find(a => a.id === txn.accountId);\nif (!account) {\n  throw new Error(`YNAB4 data inconsistent: transaction ${txn.id} references unknown account ${txn.accountId}`);\n}","typeGuard":"function isKnownAccount(accounts: { id: string }[], acctId: string): boolean {\n  return accounts.some(a => a.id === acctId);\n}","tryCatchPattern":"try {\n  await importBudget(ynab4Dir);\n} catch (e) {\n  if (e.message.includes('Could not find account for transaction')) {\n    // inspect the YNAB4 export for orphaned transactions, fix, and re-import\n  } else throw e;\n}","preventionTips":["Copy the entire YNAB4 budget directory, never a partial set of files","Pre-validate the export: every transaction accountId must exist in the accounts data","Use a single id map when remapping account/transaction ids in preprocessing scripts"],"tags":["import","ynab4","data-integrity","missing-account"],"backgroundTag":"unresolved-foreign-key-reference","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}