Skip to content
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

Allow usage of pnpm #1207

Open
dancojocaru2000 opened this issue Jun 25, 2020 · 9 comments
Open

Allow usage of pnpm #1207

dancojocaru2000 opened this issue Jun 25, 2020 · 9 comments
Labels
feature request no-stale-bot This issue cannot be marked as stale by stale bot

Comments

@dancojocaru2000
Copy link

Allow the usage on pnpm instead of yarn or npm.

Perhaps a guide for doing the init manually would be helpful until such capability is introduced.

@github-actions
Copy link

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@thymikee
Copy link
Member

thymikee commented Dec 5, 2022

Reopening, pnpm is something that we'd like to support

@thymikee thymikee reopened this Dec 5, 2022
@github-actions github-actions bot removed the stale label Dec 6, 2022
@TMisiukiewicz TMisiukiewicz added the no-stale-bot This issue cannot be marked as stale by stale bot label Dec 6, 2022
@TMisiukiewicz
Copy link
Collaborator

Hey, support for pnpm is something i have been working on for a while. I was able to make it work with init command and make project running on iOS and Android. However, since pnpm is using symlinks, I discovered a few pitfalls here.

  1. node_modules structure is different. - there is a need of manual changing the paths in the following files in android and ios folders:
  • ios/Podfile - path to native_modules
  • android/app/build.gradle - path to native_modules.gradle
  • android/settings.gradle - path to native_modules.gradle

The pnpm paths are strongly dependent on installed versions of the dependencies, e.g. .pnpm/@[email protected]/node_modules/@react-native-community/cli-platform-android/native_modules.gradle

  1. there is a need of adding the Metro resolver for symlinks: rnx-kit/metro-resolver-symlinks
  2. Developer needs to manually run pod install after initializing the project - CocoaPods installation fails due to incorrect native_modules path in Podfile mentioned in 1, but that step can be just skipped in init when using pnpm as package manager.

Another possible solution is creating a .npmrc file, adding node-linker: hoisted inside of it and running pnpm install, but i think it's missing the point of using pnpm as the node_modules structure will become similar to the one known from yarn and npm.

Where to go from there? I think adding all the required steps to make it work to the docs is one of the options, but definitely not the best one.

@rahulpandey
Copy link

rahulpandey commented Mar 10, 2024

Following steps working for me
Added public-hoist-pattern configuration in .npmrc to hoist packages from specific scopes:
.npmrc:

public-hoist-pattern[]=*@react-native-community*
public-hoist-pattern[]=*@react-native*

Also integrated the following changes in metro.config.js:

const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const path = require('path');

/**
 * Metro configuration
 * https://facebook.github.io/metro/docs/configuration
 *
 * @type {import('metro-config').MetroConfig}
 */
const projectRoot = __dirname;

const config = {
  watchFolders: [projectRoot],
  resolver: {
    nodeModulesPaths: [path.resolve(projectRoot, 'node_modules')],
  },
};
module.exports = mergeConfig(getDefaultConfig(__dirname), config);

React and React Native versions:
"react": "18.2.0",
"react-native": "0.73.5",

It seems that every Gradle command is working fine through the command line. However, when I try to sync from Android Studio, the following error is displayed: 'Missing ExternalProject for:'

@WarrenBuffering
Copy link

WarrenBuffering commented Jul 11, 2024

Are you saying these changes worked for you @rahulpandey? Or are you still getting the Missing ExternalProject for: error?

@bimusiek
Copy link

For us we had react native working with pnpm without hoisting. With new arch enabled. Then at one point of upgrading to newest RN, it stopped working with the error:

Missing ExternalProject for :

However, it works if using gradle from the command line.

@bimusiek
Copy link

Ok, I found the fix for React Native.

Instead of

includeBuild('../node_modules/@react-native/gradle-plugin')

you have to do

includeBuild(file("../node_modules/@react-native/gradle-plugin").toPath().toRealPath().toAbsolutePath().toString())

then it works in newest Android Studio.

@JDScript
Copy link

Ok, I found the fix for React Native.

Instead of

includeBuild('../node_modules/@react-native/gradle-plugin')

you have to do

includeBuild(file("../node_modules/@react-native/gradle-plugin").toPath().toRealPath().toAbsolutePath().toString())

then it works in newest Android Studio.

You saved my day!!!!

@shaquibimdad
Copy link

    "@react-native-community/cli": "^13.6.4",
    "@react-native-community/cli-platform-android": "^13.6.4",
    "@react-native-community/cli-platform-ios": "^13.6.4",
    "@react-native/gradle-plugin": "^0.74.86",

adding above deps to dev dependencies and then from @bimusiek solution for android studio

pnpm works smoothly no issues so far

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request no-stale-bot This issue cannot be marked as stale by stale bot
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants