-
Notifications
You must be signed in to change notification settings - Fork 629
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
Follow symlinks? #1
Comments
symlinks not working in React Native is one of the biggest RN complaints, so if my understanding is correct and this would fix that, this would be great! |
I think we won't have time to deal with this anytime soon unfortunately. I'd love to reopen once we have a strong case. |
Can we leave this open until it's resolved? This is a huge PITA for code sharing, and developing modules. I'm not sure what your looking for in terms of a strong case, but it's definitely a major pain point for me, and module developers. Currently I am trying to use lerna, and react-primitives to reorganize a project boilerplate to maximize code reuse, while maintaining upgradability by rn. Lerna works by symlinking and installing your packages in a mono repo, which is an incredibly helpful pattern for code reuse, and completely broken when the react native packager won't follow symlinks. |
Yeah, it should be open. We should find a fix but we are not actively invested in making this change ourselves right now. If the community can find a reasonable solution, we should merge it and make it work. |
I suspect it has to do with this line //...
this._moduleResolver = new ModuleResolver({
dirExists: filePath => {
try {
var stats = fs.lstatSync(filePath);
return stats.isDirectory() || stats.isSymbolicLink();
} catch (e) {}
return false;
},
// ... Though I am short on time for digesting how to get started with this project at the moment. I may have more time over the weekend for a proper PR. Or if someone else gets the chance to play around with it, that would be awesome. I never have enough time to accomplish all the things I want to do :( Edit: added "may", as the docs don't explicitly say you isDirectory() won't return true on a symlink, but I believe that is the case. Edit^2: https://github.com/ericwooley/symlinkTest You do need to explicitly check on OSX Sierra at least, not sure about linux or windows. Edit^3: the commit where the test was removed c1a8157 |
With |
The test was removed because it was already broken for a long time, unfortunately (I forgot to put that in the changeset description apparently). Now I realised I shouldn't have removed it completely, only make verify the broken behavior.
|
Interesting. I am pretty confused by this project, as I am not sure how it is imported by RN. But I manually edited this change into I also put a console log there to offer some insight, and it was definitely logging. So that line appears to be used by the react-native project while doing real work (as opposed to debugging). After much frustration with this issue, it ended up being easier to PR the libs i need to work with haul, rather than try to tackle this problem. I wish I had more time for this issue, but it appears to be a pretty rough one to solve, given what @jeanlauliac said. Hopefully this gets officially resolved soon. as I would much prefer to use the built in solution. On a side note, haul seems to have fixed all the symlink issues. Is there a downside to haul that you know of? It seems like it could be something that could be officially brought into the fold. |
Something that half-works is not symbolic linking but hard linking. You can't hard link directories, but you can use The only catch is that it seems in order to trigger rebundling I have to save the changed file (even though the action of saving isn't changing the contents of the file). |
@ericwooley Can you explain how your PR, haul, and storybooks (?) relate to the react-native symbolic link issue? |
@bleighb Haul is an alternative to the react-native packager that doesn't have issues with symlinks. They reference this issue because those PR's and issues are about issues with symlinking and the metro bundler. As to your cp -r issue, you might have better luck with rsync. Which is something I considered at one point. |
I'm in the lerna boat, too. The way I finally worked around this issue was to just explicitly add the packages in our monorepo to rn-cli.config.js, instead of having them as dependencies in the RN project's package.json (and symlinked into node_modules)
May have changed for Metro. HTH |
@kschzt I will have to try that solution tonight. I imagine that there will be more pressure on this issue once yarn workspaces are released. Until then, your solution may be the only way forward. |
I was unable to get things to work in something like a monorepo when trying @kschzt’s approach. If I have module
Why does it not check to see if the module exists inside the (react-native v0.45.0.) |
How are you importing your files
I'm not really sure how roots work in this context, but the way your importing may be a factor. Or are you using the |
@ericwooley 2(ish): Both the project and I are new to React Native (migrating an existing web app); I’m not familiar with the |
funny, it used to work ( |
This lerna project seems to work with Symlinks too (react-native 0.40) https://github.com/samcorcos/learna-react-native |
I have played with that too @AshCoolman, and it does seem to work, but setting it up in a similar way with other versions has not worked. |
@ericwooley My experience too |
Is the only solution at the moment to use haul or some custom shell scripts? |
This does not contain monorepo configs, but should work the same. I'll test later today. Updating for pnpm & Expo SDK 49 users: npmrc:
Metro config: // Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require("expo/metro-config");
const MetroSymlinksResolver = require("@rnx-kit/metro-resolver-symlinks");
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname, {
// [Web-only]: Enables CSS support in Metro.
isCSSEnabled: true,
});
config.resolver.resolveRequest = new MetroSymlinksResolver();
module.exports = config; |
Hi @sannajammeh
When I run npm start and open the app in Expo GO, it is still showing something like |
This is working on my PC. https://github.com/sannajammeh/expo-49-test/tree/pnpm If its not working, try force installing with |
Same here, except I'm using the bare typescript template. |
@rollingmoai hi, I tried sannajammeh's solution and it works:
|
is yarn workspaces supported? I didn't manage to make it running. If i add my packages to watchFolders as this
it works but as i understand it avoids symlinks in node_modules and just takes it from actual location. |
Summary: Flip the default for `unstable_enableSymlinks` to true. The option was made available in React Native 0.72 and it's been trialled by the community to the extent that we can have good confidence in it (though there are still devx gaps to guide users towards a suitable configuration). This is also an effective prerequisite for disabling Haste/global package resolution by default in OSS, which currently allows workspaces to mostly-work in the absence of symlink support. Closes facebook#1 Changelog: ``` - **[Feature]**: Enable resolution through symlinks (previously experimental `unstable_enableSymlinks`) ``` Differential Revision: D48777855 fbshipit-source-id: 8da1ab84d2971736ec2560aae4a82294aec6da9f
…book#1068) Summary: Pull Request resolved: facebook#1068 Flip the default for `unstable_enableSymlinks` to true. The option was made available in React Native 0.72 and it's been trialled by the community to the extent that we can have good confidence in it (though there are still devx gaps to guide users towards a suitable configuration). This is also an effective prerequisite for disabling Haste/global package resolution by default in OSS, which currently allows workspaces to mostly-work in the absence of symlink support. Closes facebook#1 Changelog: ``` - **[Feature]**: Enable resolution through symlinks (previously experimental `unstable_enableSymlinks`) ``` Reviewed By: motiz88 Differential Revision: D48777855 fbshipit-source-id: a11664bac127db931c03d0e8446b6fc66e3c8a2b
Issue closed? Any help on how I can use pnpm with |
Hi folks - this issue is closed because symlinks are now supported in Metro Note that all source files and assets must be "watched" by Metro - so if you have symlinks to paths outside your project root (the directory containing your Note also that full, non-hoisted PNPM/Yarn workspace support in React Native is still a work in progress and currently requires workarounds - not because of symlinks, but rather different package layouts that break some assumptions in Xcode and Gradle scripts, etc. We're working on that for RN 0.73. Otherwise, please do open a new issue for any problems you run into. |
@robhogan Hi there, thanks for your answer. I have "metro-react-native-babel-preset": "0.76.8" and RN 0.72.4 symlinks are created by yarn in node_modules folder of root level. And metro can't resolve them. My metro.config.js has this settings:
], |
But where does To be clear, it's not sufficient to watch the symlink itself - you need to be watching the symlink target. |
@robhogan watchFolders contains path to all npm packages and symlinks. I saw it in a bunch of articles trying to configure it. This looks strange to me. If i have to watch the path to actual packages, then why do we need unstable_enableSymlinks property and symlinks themself. |
Hey @skurgansky-sugarcrm, it sounds like you might be expecting symlink support to work differently, but I'm not sure that you're facing a problem with it. There is some overlap between the functionality provided by symlinks vs Haste packages that make this a bit complicated, but symlink support is intended to provide symlink-traversing resolution similar to Node JS and other tools, as necessary for the likes of pnpm. It's not intended as a mechanism to have source outside If you want to chat about the implementation and design or if you do have a specific problem, feel free to open a new issue - this one has a lot of subscribers and I'm keen to avoid noise. |
in .npmrc is needed when using
will be thrown. But with this config, still getting error
uninstall |
This was very time consuming for me to debug and figure out why symlinks were not working. For others who might be having similar issues:
Most of this was gleaned from here: #1 (comment)
|
For those on Expo SDK 50 + RN 0.73 + pnpm trying to use the new symlinks support (without |
@karlhorky I managed to get this working here pnpm/pnpm#4286 (comment). |
@lbxa nice, thanks for spending the time documenting that! |
For official first-class support in Expo, it looks like non-hoisted pnpm support is scheduled for Expo SDK 52 - mentioned in @byCedric's post in the pnpm repo: |
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
I'm removing a test from
DependencyGraph-test
that looked like so, but wasn't actually working after I fixed problems with thefs
mocks:What is the expected behavior?
Reintroduce the test and verify symlinks work.
The text was updated successfully, but these errors were encountered: