gatsbyjs/gatsby · error

Result of a worker should be an object, type of "${typeof re

Error message

Result of a worker should be an object, type of "${typeof result}" was given

What it means

After a job runs, the manager requires the worker result to be a plain object (or null) so it stays consistent for Gatsby Cloud serialization. Any other type (string, number, boolean, array, class instance) throws.

Source

Thrown at packages/gatsby/src/utils/jobs/manager.ts:306

      0
    )
    activityForJobsProgress.start()
    activitiesForJobTypes.set(jobType, activityForJobsProgress)
  } else {
    activityForJobsProgress.total++
  }

  const deferred = pDefer<Record<string, unknown>>()
  jobsInProcess.set(job.contentDigest, {
    id: job.id,
    deferred,
  })

  try {
    const result = await runJob(job)
    // this check is to keep our worker results consistent for cloud
    if (result != null && !_.isPlainObject(result)) {
      throw new Error(
        `Result of a worker should be an object, type of "${typeof result}" was given`
      )
    }
    deferred.resolve(result)
  } catch (err) {
    deferred.reject(new WorkerError(err))
  } finally {
    // when all jobs are done we end the activity
    if (--activeJobs === 0) {
      hasActiveJobs!.resolve()
      activityForJobs!.end()
      // eslint-disable-next-line require-atomic-updates
      activityForJobs = null
    }

    activityForJobsProgress.tick()
  }

View on GitHub (pinned to 8b06340921)

Solutions

  1. Return a plain object from the worker: {} or { value }.
  2. Wrap primitives: return { url } instead of url.
  3. Convert arrays/instances to plain objects before returning.

Example fix

// before: worker returns a string
module.exports.PROCESS = async (job) => transform(job).url
// after: return a plain object
module.exports.PROCESS = async (job) => ({ url: transform(job).url })
Defensive patterns

Strategy: validation

Validate before calling

const _ = require('lodash')
function assertPlainObjectResult(result) {
  if (result != null && !_.isPlainObject(result)) {
    throw new Error(`Worker must return a plain object, got ${typeof result}`)
  }
}

Type guard

function isPlainObjectOrNull(v) { return v == null || _.isPlainObject(v) }

Prevention

When it happens

Trigger: A worker function returns a primitive (e.g. a URL string) or an array instead of a plain object.

Common situations: Plugin worker returning a string URL instead of { url }; returning an array of paths instead of { paths }; returning a class instance.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/cdd2ce08515fdb34. Report an issue: GitHub.