React Native + PNPM Workspaces: "Cannot read property 'prototype' of undefined"

85 Views Asked by At

Overview

I have an Expo project running in a pnpm workspace, and get the error ERROR TypeError: Cannot read property 'prototype' of undefined, js engine: hermes when adding Firebase and using anything from Firestore. I cannot for the life of me get this to work without disabling shared-workspace-lockfile. I'm not entirely sure if this is an issue with Firebase itself, but it is the only package that's given me this issue.

The error is ostensibly at @firebase/firestore/dist/index.rn.js (5826:1), but I can't find anything in there to patch.

Minimum Reproducible Example

apps/test/App.tsx

import React from "react";
import { Text, View } from 'react-native';
import { FieldPath } from "firebase/firestore";


export default () => {
  // Literally anything from firebase/firestore that isn't shaken out
  FieldPath;

  return (
    <View>
      <Text>
        HELLO WORLD
      </Text>
    </View>
  );
};

.npmrc

node-linker=hoisted
auto-install-peers=true 
shared-workspace-lockfile=true

apps/test/package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "clean": "rm -rf node_modules",
    "start": "expo start"
  },
  "keywords": [],
  "author": "",
  "dependencies": {
    "expo": "^49.0.21",
    "expo-device": "~5.4.0",
    "firebase": "^10.7.1",
    "lodash": "^4.17.21",
    "react-dom": "^18.2.0",
    "react-native": "0.72.6",
    "react-native-web": "~0.19.10",
    "typescript": "^5.3.3"
  },
  "devDependencies": {
    "@babel/core": "^7.23.2"
  }
}

apps/test/index.js

import registerRootComponent from 'expo/build/launch/registerRootComponent';

import App from './App';
registerRootComponent(App);

apps/test/metro.config.js

// Learn more: https://docs.expo.dev/guides/monorepos/
const { getDefaultConfig } = require("@expo/metro-config");

const path = require("path");

const projectRoot = __dirname;
const workspaceRoot = path.resolve(projectRoot, "../..");

// Create the default Metro config
const config = getDefaultConfig(projectRoot, { isCSSEnabled: true });

if (config.resolver) {
  // 1. Watch all files within the monorepo
  config.watchFolders = [
    workspaceRoot,
    //path.resolve(workspaceRoot, "node_modules"),
  ];
  // 2. Let Metro know where to resolve packages and in what order
  config.resolver.nodeModulesPaths = [
    path.resolve(projectRoot, "node_modules"),
    path.resolve(workspaceRoot, "node_modules"),
  ];
  // 3. Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths`
  config.resolver.disableHierarchicalLookup = true;

  config.resolver.extraNodeModules = [
    path.resolve(workspaceRoot, "node_modules"),
  ];

  config.resolver.sourceExts = [
    'jsx', 'js', 'ts', 'tsx', 'cjs', 'mjs', 'json'
  ];
}

module.exports = config;

Stack Trace

stack_trace

0

There are 0 best solutions below