Skip to content

Conversation

@bheemreddy-samsara
Copy link
Contributor

@bheemreddy-samsara bheemreddy-samsara commented Jan 8, 2026

Description

Adds Object.hasOwn polyfill to the runtime package for Hermes compatibility.

Hermes (React Native's default JS engine) doesn't support Object.hasOwn (ES2022). This causes runtime errors when @vitest/expect v4.x initializes:

Object.hasOwn is not a function. (In 'Object.hasOwn(globalThis, MATCHERS_OBJECT)', 'Object.hasOwn' is undefined)

Related Issue

Fixes #51

Context

The error originates from @vitest/expect/dist/index.js:674:

if (!Object.hasOwn(globalThis, MATCHERS_OBJECT)) {

Since react-native-harness targets React Native (which uses Hermes by default) and depends on @vitest/expect v4.x, the polyfill belongs in the harness runtime rather than requiring every consumer to add it.

The polyfill is minimal and standards-compliant:

if (typeof Object.hasOwn !== 'function') {
  Object.hasOwn = (obj: object, prop: PropertyKey): boolean =>
    Object.prototype.hasOwnProperty.call(obj, prop);
}

Testing

  • Tested on Android emulator with Hermes enabled
  • Harness tests pass after adding this polyfill

References

Hermes (React Native's default JS engine) doesn't support Object.hasOwn
(ES2022). This causes runtime errors when @vitest/expect v4.x initializes
because it uses Object.hasOwn internally.

Error without fix:
```
Object.hasOwn is not a function. (In 'Object.hasOwn(globalThis, MATCHERS_OBJECT)', 'Object.hasOwn' is undefined)
```

Add polyfill in runtime package that loads before @vitest/expect.

Tracking: facebook/hermes#1875
@vercel
Copy link

vercel bot commented Jan 8, 2026

@bheemreddy-samsara is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@bheemreddy-samsara bheemreddy-samsara marked this pull request as draft January 8, 2026 19:44
@bheemreddy-samsara bheemreddy-samsara deleted the fix/hermes-object-hasown branch January 8, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime crashes on Hermes: Object.hasOwn is not a function

1 participant