-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Flow doesn't recognize platform-specific react-native files #945
Comments
+1 |
Yup, this is super valuable. We should have a solution for this. |
Not sure what the proper way to "upvote" this would be. But: |
Would be great to see this being worked on. Ideally this should be configurable to support different platforms like |
Just recently started converting a React Native project into flow and encountered this. +1 |
I just ran into this as well. |
Another workaround is to add the following to .flowconfig:
Of course you'll have to edit this if you want to check .android or .web |
I think this issue can be closed as |
I still see an issue here: how can flow validate all files? I mean flow might want to choose .ios.js first, but this might leads to issue if someone update another ext (ex: .web.js, defined after) and do not respect the API of .ios.js version. |
@MoOx Flow will need to run through all three code paths. I don't think this works now, but it could work like this
Maybe you could do it now with 3 different .flowconfig |
Thanks for the alternative suggestion @dalejefferson, could you please elaborate on how this works for you? I just get |
@bkrem I think there is just a typo, try --file-ext. |
It does not work for me, I was just suggesting that it could work like that. |
Ah right just a misunderstanding, I thought you meant the suggestion above yours was deprecated rather than your own being a suggestion :) |
The problem using the config is that flow will stop on the first file it will find. So if you .ios.js is the first, flow won't check other implementations. That's why trying to do that for each extensions might be a good idea. |
|
@mhollweck the problem is that flow will stop for the first file it will find. It won't resolve and try multiple files. So you might need to use flow with multiples config or try using a CLI options to run flow 2 times... (or maybe use ios by default and run 1 additional time with .android.js)... |
@MoOx I know that flow only checks the first file it will find but even if I ONLY check android files it won't recognise my android.js files! Am I the only person with this issue? |
@mhollweck : React Native's default .flowconfig is set up to ignore all .android.js files. You can work around this by changing |
Any progress on this? I currently have this issue with react-native 0.35 and flow-bin 0.32 |
I spent a bit of time seeing if I could get a quick fork with a fix, but I don't understand ocaml. Seems to me like someone with more experience could undo the
would resolve any This feature is critical for a pattern I'm using to share web and native code as a single module. Really hoping someone will help soon! |
Being able to add filetype/extension specific options should be able to solve this problem.
Of course, some other variants may work better for configuring the extension type for options, perhaps |
2015? mm ok. |
Can anyone please update as to why React Native's .flowconfig is configured in a way to ignore |
I would like to know the reasoning as well |
If I add |
For React Native 0.46.4+ version name your ios components with a regular name |
@eclipticwld it doesn't seem fine to me. The .flowconfig generated by the React Native CLI still opens as follows:
This will be "fine" only in the sense that Flow will ignore any Android specific files in your project. |
@fagerbua I see. |
@eclipticwld @fagerbua That is not an issue related to flow, that is more like a react-native issue, in order to make flow run through my app on android I avoid running flow in react-native by ignoring react-native in my |
I was hoping that If my config is:
And I have these files:
Then importing |
any progress on this? |
1 similar comment
any progress on this? |
any progress on this? (since more than 3 years issue opened and almost year of last comment) |
The workaround works for me, but the dependencies usually show up as "unused import" |
For a while React Native itself has been getting around this with 2 separate .flowconfig files, which are run as independent checks:
To me this doesn't seem like an unreasonable approach... the way RN forks off platform-specific versions of modules is essentially a way to create different projects per platform, so it's a fair trade-off that they need to be typechecked independently. I generally use the in-code
I'm not sure this is really in-line with what RN itself does. From what I see e.g. here: facebook/react-native#22990 it looks like they're now more moving towards |
cc @TheSavior Do you have any opinion on what could be best approach for Flow here? And with the new native codegen, is RN moving away from |
With react-native, it's theoretically possible to have completely separate sets of JavaScript source-code files for ios and android if you have an index.ios.js and an index.android.js. https://stackoverflow.com/questions/50272240/does-react-native-perform-tree-shaking is also relevant here. |
Part of the RN v0.59.10 -> v0.60.0 upgrade [1]. This commit has no hard constraints on its position relative to the others in the series, but at least one change (the `HMRLoadingView.js` ignore) is not necessary until the upgrade. Corresponds to facebook/react-native@0f909e331. Leave in one inexplicable line that reveals huge numbers of errors if removed, mostly in node_modules/react-native/Libraries (but some in our code as well, e.g., `deprecated-utility` on the use of `$Subtype` in `redux-persist/index.js.flow`. ```diff - module.file_ext=.js - module.file_ext=.jsx - module.file_ext=.json - module.file_ext=.native.js module.file_ext=.ios.js // This line ``` It's not there in the RN v0.60.0 template, but it's been in our repo since e38869a, the upgrade from RN 0.51.0 to 0.52.0. It doesn't seem to have ever been in the template app. The upgrade helper showing the `rn-diff-purge` diff from RN 0.51.0 to 0.52.0 [1] doesn't suggest adding that line, but I don't think that tool was around when that other upgrade was done. Perhaps it was added from experimentation, or there was another guide to upgrading. Anyway, there's an open Flow issue [2], which was open at the time of e38869a, one resolution of which is to include the line that was included. So, keep including it. [1]: https://react-native-community.github.io/upgrade-helper/?from=0.51.0&to=0.52.0 [2]: facebook/flow#945
We now have experimental support for this. https://flow.org/en/docs/react/multiplatform |
In recent react-native releases, common practice for files that need platform-specific implementations is to turn
foo.js
into two files:foo.android.js
andfoo.ios.js
. Flow obviously doesn't know what to make of this, which leads to "Required module not found" errors.As a temporary workaround you can add
module.name_mapper
for each such file, but maintaining this list is a lot of work, and the end result is that half your code isn't type-checked at all.Ideally, flow would recognize this pattern, and be able to type-check both implementations against the import (and against each other) to ensure they implement the same interface.
The text was updated successfully, but these errors were encountered: