Error when using new RTCPeerConnection(peerCons) constructor

hello everyone,

when calling const pc = RTCPeerConnection(peerCons) constructor, the error below occurs.
it works as soon as i delete that code.

react-native-webrtc version: 118.0.1
react-native version: 0.73

i’m using expo prebuilt.

i have used react-native-webrtc 111.0.0 and older versions as well, it was working without issues.

has anyone came across this situation?


ERROR TypeError: Super expression must either be null or a function, js engine: hermes

ERROR Invariant Violation: “main” has not been registered. This can happen if:

  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.

  • A module failed to load due to an error and AppRegistry.registerComponent wasn’t called., js engine: hermes

1 Like

I’m having this exact problem!!!

have you found a workaround or fix?

yes, i found the solution, create metro.config.js and paste the code below, that's it

const { getDefaultConfig } = require("expo/metro-config");
const resolveFrom = require("resolve-from");

/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);

config.resolver.resolveRequest = (context, moduleName, platform) => {
  if (
    moduleName.startsWith("event-target-shim") &&
    context.originModulePath.includes("react-native-webrtc")
  ) {
    const eventTargetShimPath = resolveFrom(
      context.originModulePath,
      moduleName
    );

    return { filePath: eventTargetShimPath, type: "sourceFile" };
  }

  return context.resolveRequest(context, moduleName, platform);
};

module.exports = config;

^ Acceptable solution for anyone using Expo, it would be slightly different for other users.
We’re working on fixing the issue once and for all in a future release.
One of them annoying issues which not everyone seems to experience.