Migrate Expo to monorepo cause "Invalid hook call" error

22 views Asked by At

I have an Expo app, created a few years ago and running in production.

Today I want to migrate this app in a monorepo, handled with PNPM workspaces, with others app (NestJS, React, ...) sharing the sames custom librairies.

All my apps works fine, except my Expo app. When I try to run it with Expo Go or development build, I got this error :

Error: Invalid hook call. Hooks can only be called inside of the body of a function component

But I didn't edit my code so I know it works, cause it's in production.

From my research, I put a .npmrc file on my monorepo's root with this this instruction : node-linker=hoisted.
Also I've created a metro.config.js file with this content :

const { getDefaultConfig } = require('expo/metro-config');
const path = require('path');

const projectRoot = __dirname;
const monorepoRoot = path.resolve(projectRoot, '../..');

const config = getDefaultConfig(projectRoot);

config.watchFolders = [monorepoRoot];
config.resolver.nodeModulesPaths = [
  path.resolve(projectRoot, 'node_modules'),
  path.resolve(monorepoRoot, 'node_modules'),
];

module.exports = config;

And changed the entrypoint of my app in my package.json to point to a new index.ts file with this content :

import { registerRootComponent } from 'expo';
import App from './App';

registerRootComponent(App);

I think I've followed required steps from official documentation : https://docs.expo.dev/guides/monorepos/

But still not works.

I found some issues saying it can be a conflict between different versions of react on the same project, but react and react-dom are installed on the Expo application's node_modules to override any other versions.

I'm not very familiar with monorepos, put I think it's sufficient, isn't it ?

Thank's for your help.

0

There are 0 answers