Budibase/budibase · error · HTTPError

Project package resource count mismatch for '${resourceType}

Error message

Project package resource count mismatch for '${resourceType}'.

What it means

As a final integrity check, the importer counts the imported docs by resource type and compares against manifest.resourcesByType from project.json (imports.ts:807-830). The root project itself is pre-counted as one PROJECT doc. Any type whose actual count differs from the manifest count (in either direction, over the union of seen types) produces this 400 error naming the mismatched type.

Source

Thrown at packages/server/src/sdk/workspace/projects/backups/imports.ts:825

  const countedResources = docs.reduce<Partial<Record<ResourceType, number>>>(
    (acc, doc) => {
      acc[doc.resourceType] = (acc[doc.resourceType] || 0) + 1
      return acc
    },
    { [ResourceType.PROJECT]: 1 }
  )

  const resourceTypes = new Set([
    ...Object.keys(countedResources),
    ...Object.keys(manifest.resourcesByType),
  ])

  for (const resourceType of resourceTypes) {
    const actualCount = countedResources[resourceType as ResourceType] || 0
    const expectedCount =
      manifest.resourcesByType[resourceType as ResourceType] || 0
    if (actualCount !== expectedCount) {
      throw new HTTPError(
        `Project package resource count mismatch for '${resourceType}'.`,
        400
      )
    }
  }
}

const assignImportedIds = (docs: ImportedDoc[], idMap: Map<string, string>) => {
  for (const resourceType of PREASSIGNED_IMPORT_TYPES) {
    for (const importedDoc of docs.filter(
      doc => doc.resourceType === resourceType
    )) {
      idMap.set(
        importedDoc.doc._id!,
        generateImportedId(resourceType, importedDoc.doc, idMap)
      )

      if (resourceType === ResourceType.ROW_ACTION) {

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Regenerate the package so project.json's resourcesByType is computed from the actual exported docs.
  2. Update resourcesByType in project.json to match the real doc counts per type (remember the PROJECT type counts the root project doc).
  3. Add or remove doc files so counts match the manifest for the type named in the error.
  4. Audit counts with a quick script: group doc files by type and diff against `jq .resourcesByType project.json`.

Example fix

// project.json before
"resourcesByType": { "table": 3, "datasource": 1 }
// after (only 2 tables shipped)
"resourcesByType": { "table": 2, "datasource": 1 }
Defensive patterns

Strategy: validation

Validate before calling

const counts = {}
for (const d of pkg.docs) counts[d.resourceType] = (counts[d.resourceType] || 0) + 1
counts.project = (counts.project || 0) + 1 // root project doc
for (const [type, n] of Object.entries(pkg.manifest.resourcesByType)) {
  if ((counts[type] || 0) !== n) throw new Error(`Count mismatch for ${type}: docs=${counts[type] || 0}, manifest=${n}`)
}

Try / catch

try {
  await importProjectPackage(file)
} catch (e) {
  if (e.status === 400 && e.message.includes("resource count mismatch")) {
    // read the named type from the message and fix docs or manifest counts
  } else throw e
}

Prevention

When it happens

Trigger: Importing a package where the number of docs of some resource type (e.g. tables, datasources, screens, rows) differs from the count declared in project.json's resourcesByType — docs added/removed without updating the manifest, or the manifest counted resources later excluded from the package.

Common situations: Manually adding or deleting doc JSONs from the archive; unsupported resources filtered out during a partial export but still counted; hand-edited project.json counts; exports produced by custom tooling with stale tallies.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/36dced738d122186. Report an issue: GitHub.