-
Notifications
You must be signed in to change notification settings - Fork 607
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
[rush] How to use with React Native? #1025
Comments
I suppose we could have a setting that instructs Rush to run However, how would this work for locally-linked library projects? Or do you only need it for your top-level application? BTW I am aware of people successfully using Rush with React Native, however I don't have experience with this myself. @acoates-ms did your group do anything special to get this working? |
@acoates-ms: Thanks for the info! I tried using However, I could not get it to work with React Native's tooling which seems to not find symlinked modules before @pgonzal: I was looking for something like the "nohoist" option of yarn's workspaces. Here is a good explanation: "Yarn Blog nohoist in Workspaces" Maybe something similiar could be implemented in Rush? |
@joerneu we would certainly accept a PR to add this sort of functionality to (That said, I personally have spent a ton of time dealing with frustrating consequences of NPM doppelgangers and was very happy to finally eliminate them from our monorepos. Yarn/Lerna's installation strategies reintroduce these sorts of problems: "nohoist" causes doppelgangers, and if you do "hoist" it causes phantom dependencies which are also problematic. So if I was going to invest in this, I'd prefer to spend my time fixing React Native to correctly support the NodeJS module resolution standard, versus building these sorts of accommodations in Rush. But of course I recognize that this might not be the cheapest path to get React Native working, and I would of course vote for any PR that helps with that goal.) |
Hi! Our team is considering adopting Heft to manage our RN monorepo. Did someone here manage to successfully build a React Native app using Heft? |
I met this issue too, waiting for solutions😭 |
We've made some progress here. This package will add symlink support to metro: |
@acoates-ms THANK YOU. that works wonderfully! @zkochan can we add this ^ to the docs? |
sure, we should add some recipe page for React Native. |
Anyone have any luck getting a React Native app running with Rush + pnpm? Seeing the following error:
Looks like metro doesn't resolve the root properly. I have tried configuring the |
For our use case, Rush + pnpm + repack seems to do the trick for us. Was never able to get metro working with our package structure even with the above advice. |
Since recently pnpm also has a node-linker=hoisted option. So if nothing helps, |
Hey @zkochan, I have a couple of quick questions about the setting you mentioned, I haven't quite gotten a chance to play around with it:
Thank you for all you do to make the experience of developers working in JS/TS monorepos better. Pnpm has been a lifesaver for us! I will create a minimal example using the tooling I described above when I get a chance. |
I don't have benchmarks but it seems fast.
It will work
It will be shared. It will be hoisted to the root of the monorepo. |
Ended up ditching this config, it was really brittle when adding dependencies. Ended up getting errors out of repack that weren't of any help whatsoever. Fell back to removing my RN app from the rush config and using yarn to manage the dependencies. Wired in all the local dependencies in using the Yarn I haven't tried pnp yet, but I have a feeling even if I did get the RN tooling working, other parts of the monorepo would probably explode. |
HBO is successfully using Rush+PNPM+ReactNative at my work. We're using @vjpr's patches but rolled up into a reusable adapter. Maybe we could share it, or at least add a ReactNative sample project in https://github.com/microsoft/rushstack-samples/ |
This would be amazing |
Update: After testing I don't think this actually works properly, as it's just naively including modules from the first match it finds in the watchFolders regardless of if the version number matches or not.
const { makeMetroConfig } = require('@rnx-kit/metro-config');
const MetroSymlinksResolver = require('@rnx-kit/metro-resolver-symlinks');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const path = require("path");
const config = makeMetroConfig({
projectRoot: __dirname,
resolver: {
// ignore projects folder since it contains package.json files with module name + version that clash with the workspace package.json files
blacklistRE: exclusionList([/temp\/projects\/.*/]),
resolveRequest: MetroSymlinksResolver(),
},
});
// Remove first element, which is always the repo root;
config.watchFolders.shift();
// Remove the project root, as it's already being watched by metro
config.watchFolders = config.watchFolders.filter(folder => folder !== __dirname);
// Add rush common/temp directory as shared node modules live here;
// many other package node_modules are symlinked to this location
config.watchFolders.push(path.resolve(__dirname, "../../common/temp"));
module.exports = config;
|
@octogonz please do |
Hi ! |
I am trying to setup a monorepo with React Native projects.
The React Native packager is not able to follow symlinks. Even with workarounds for linked projects (see reference below) React Native's packager cannot resolve React Native's own packages if "react-native" is symlinked.
To solve this I have been using the "nohoist" option of yarn's workspaces. With this option some packages are not symlinked and will be installed in the project's node_modules folder.
Is there a way to tell Rush to place some packages in the project's node_modules folder instead of the symlinked shared folder?
Any other workaround?
References:
Similiar PNPM issue with React Native and symlinks
React Native's packager issue with symlinks
The text was updated successfully, but these errors were encountered: