remix-run/remix · error · TypeError
ERR_INVALID_RETURN_VALUE
ERR_INVALID_RETURN_VALUE
Error message
Expected instance of Promise to be returned from the "promiseFn" function but got type ${typeof promise} (${stringify(promise)}). What it means
When assert.promise() receives a function, it calls it and requires the return value to be a genuine Promise instance. If the function returns a thenable-less value (or a custom thenable that isn't a Promise), it throws ERR_INVALID_RETURN_VALUE.
Source
Thrown at packages/assert/src/lib/assert.ts:614
actual: e,
expected: expectedError,
operator: 'doesNotThrow',
generatedMessage: false,
},
false,
)
}
throw e
}
}
function getPromise(value: (() => Promise<unknown>) | Promise<unknown>): Promise<unknown> {
if (typeof value === 'function') {
let promise = value()
if (!(promise instanceof Promise)) {
throw createNodeTypeError(
'ERR_INVALID_RETURN_VALUE',
`Expected instance of Promise to be returned from the "promiseFn" function but got type ${typeof promise} (${stringify(
promise,
)}).`,
)
}
return promise
}
if (!(value instanceof Promise)) {
throw createInvalidArgumentTypeError(
'promiseFn',
'of type function or an instance of Promise',
value,
)
}
View on GitHub (pinned to 9696913134)
Solutions
- Ensure the function returns a native Promise (async functions or Promise.resolve(...))
- Await or wrap third-party thenables: Promise.resolve(thenable)
Example fix
// before assert.promise(() => fetchLater()) // returns undefined // after assert.promise(() => Promise.resolve(fetchLater()))
Defensive patterns
Strategy: type-guard
Validate before calling
let result = promiseFn() if (!(result instanceof Promise)) result = Promise.resolve(result)
Type guard
const returnsNativePromise = (fn: () => unknown): fn is () => Promise<unknown> => fn() instanceof Promise
Prevention
- Always return the promise from the function passed to assert.promise
When it happens
Trigger: assert.throws-like usage where promiseFn returns undefined, a plain value, or an object with a .then that is not a native Promise.
Common situations: Async functions transpiled/monkey-patched to return non-native thenables in test environments, or forgetting to return the promise inside the function.
Related errors
AI-assisted analysis of remix-run/remix@9696913134 (2026-08-27).
Data as JSON: /api/errors/78d618249ba6888e.
Report an issue: GitHub.