-
-
Notifications
You must be signed in to change notification settings - Fork 936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] - Pnpm not working with expo #4286
Comments
Try with the |
It works this way, but isn't it contrary to the principle of operation of pnpm? The purpose of pnpm is to use symlinks to reduce the size of |
Right. But we can't fix issues in third party libs. The global store is still used. Even with hoisted linker |
This is interesting! |
Can someone explain further? When using Running the app this way immediately complains about not finding Expo: 44 |
Relevant expo/expo#16104. |
That's not an issue related to pnpm, or Expo. It's just how Metro explains it can't find packages. I got it working with the |
Thanks. I actually looked into that just now and these are the specific changes necessary for pnpm: |
@byCedric now that Expo SDK 50 uses React Native 0.73 (which made the Metro symlinks support stable, which has been reported as working by the community without Expo), would it be considered a bug in Expo for pnpm support to not work out of the box (without The way I understand it, the work involved on Expo's side for supporting symlinks would be refactoring the following:
Would be great to be able to use Expo + the new Metro symlink support without the |
@zkochan alternatively, if Expo will not do the work above to support symlinks, would Some users have reported
eg. the following (not tested as working yet) public-hoist-pattern[]=*expo*
public-hoist-pattern[]=*react-native-gradle-plugin*
public-hoist-pattern[]=*@react-native-community/cli-platform-android*
public-hoist-pattern[]=*@react-native-community/cli-platform-ios* I know that |
Yes, @karlhorky is correctly, my project is working good using I'm using a default expo project created inside the monorepo using turborepo with pnpm. My
In my expo project, I have the And my
In my project, the typescript path mapping configuration (ex: |
@wesleyfreit Thanks for the above! It worked well for me with Here is my config for anyone who wants to use Expo and pnpm without a monorepo: .npmrc
metro.config.js
|
@wesleyfreit @watadarkstar these two configurations are not following my suggested
The point of issues like this are to try to move past the historical limitation of React Native to not work with symlinks and pnpm's default |
@karlhorky I tried it without the Maybe I need to delete my
|
You are correct. I had Nonetheless if I get rid of Anyway, I actually prefer this since it catches all packages even though its not super efficient: .npmrc
metro.config.js
|
I'm working in a pnpm monorepo and running the app on iOS worked for me with just config.resolver.resolveRequest = (context, moduleName, platform) => {
if (
platform === 'android' &&
// replace `packages/app` with the path to your app directory in monorepo
context.originModulePath.endsWith('packages/app/.') &&
// some weird edge cases, there might be a better way to do this
!moduleName.startsWith('/') &&
!moduleName.startsWith('../../') &&
!moduleName.startsWith('./../../')
) {
// just tell metro to look in the root of the monorepo where pnpm stores all node_modules
moduleName = `../../${moduleName}`
}
// use default
return context.resolveRequest(context, moduleName, platform)
} This is a bit hacky but it works great in a pnpm workspaces monorepo with just
const path = require('node:path')
const { getDefaultConfig } = require('expo/metro-config')
const workspaceRoot = path.resolve(__dirname, '../..')
const projectRoot = __dirname
const config = getDefaultConfig(projectRoot)
config.watchFolders = [workspaceRoot]
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, 'node_modules'),
path.resolve(workspaceRoot, 'node_modules'),
]
config.resolver.disableHierarchicalLookup = true
config.resolver.sourceExts.push('cjs')
config.resolver.resolveRequest = (context, moduleName, platform) => {
if (
platform === 'android' &&
// replace `packages/app` with the path to your app directory in monorepo
context.originModulePath.endsWith('packages/app/.') &&
// some weird edge cases, there might be a better way to do this
!moduleName.startsWith('/') &&
!moduleName.startsWith('../../') &&
!moduleName.startsWith('./../../')
) {
// just tell metro to look in the root of the monorepo where pnpm stores all node_modules
moduleName = `../../${moduleName}`
}
// use default
return context.resolveRequest(context, moduleName, platform)
}
module.exports = config |
pnpm version:
6.28.0
Code to reproduce the issue:
Expected behavior:
Be able to run an expo app without any issue.
Actual behavior:
Additional information:
node -v
prints: 16.13.2The text was updated successfully, but these errors were encountered: