-
Notifications
You must be signed in to change notification settings - Fork 204
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
React Native platform extensions #90
Comments
I wonder if this is a general bug in the plugin or something specific in react-native. I heard in the past that plugins which overrides the paths don't really work in react-native. |
@tleunen Any updates on this? I have the same problem. |
Sorry, I'm checking it this weekend. I've been really busy for these past 2 weeks that I have quite a few things to catch up with my OSS projects. |
I appreciate for the time you spent on this. It's been really helpful for me. I was thinking if I can fork and create a specific version for React Native where I can resolve modules depending on the result of RN's Platform.OS. |
Forget about it, it did not work. |
It might be something with react native. I remember a ticket saying it was hard to make it work with react native. Here it is #29 I've tested the custom extensions and everything is working fine. requiring I'd need more information to reproduce the issue, but it looks like the plugin doesn't run in your RN setup. |
Closing it because using a custom extension works fine. Let me know if there's anything I can do to help, but my knowledge of RN is very limited. |
@tleunen I tried to switch from module-alias to module-resolver today and this seems to be a bug.
requring file with extension inside a file with extension is actually broken. eg:
|
Would it be possible fo your to setup a very small project to reproduce the issue? |
sure. let me create a small repro for you. |
@tleunen here: https://github.com/chirag04/moduleResolver. It should be self explanatory. let me know if i can help you debug this. Appreciate your help 👍 |
Gracias! I'll take a look when I get a moment this week. |
@chirag04 Could you explain a bit how I'm supposed to test? I see the import 'component' and I believe that's what should trigger the error, right? |
ideally import 'component' should not trigger the error. It is erroring out currently and thats the bug i think. To test: you can simply run |
I got an error, then I run it with But I see the android version of the components. I'm guessing it's because it picks the first file, wich is android? How does this work usually with RN? Should it pick the right file based on the platform? I set a log in the module-resolver plugin and it seems the resolver works fine, except maybe it always pick android:
|
yeah. so that's the bug. RN packager picks the right |
Gotcha, I'll see if it's possible to grab an environment variable from RN to know which platform is built, and maybe add a new option in the plugin to set it in a "RN" mode. |
I don't know the internals but maybe you can let the rn packager handle this part? |
Hmm.. Thanks, it made me rethink a bit how the custom extensions work. I think it's a little bit buggy right now. But at the same time, if the user sets a custom extension, the extension should be printed in the resulted path, in order for NodeJS or any other tooling system to pick it without issue. I'm still not sure how to handle properly the case for RN. |
@tleunen wondering if you were able to resolve this? |
No, not really... :/ Not sure how to properly fix the issue. |
My issue is similar, but in my case, babel resolver is not working at all. I have the same babel config as above comments
problem:
That looks like it's not working, or maybe I'm missing something in the config |
Just find out. Since react-native version 0.41.2 , there no need for babel stage-0 and es2015. reactive-native already built in some of those features. So if you want babel-plugin-resolver to work. should not include those presets in your babel config. This is what it should look like. This example doesn't mean to be a solution for the original issue. But rather an example of how to config babel-plugin-resolver with react-native
|
I'm still not sure how we can detect which file to load ( |
@tleunen I don't think this module should do the detection tho unless there is a reason to do so. react native packager handles this correctly. |
I think I found a way to tackle this issue. Until now my way to make the plugin work was to add an empty The solution I propose is to add a configuration option to the plugin like The configuration for a RN project could look like : [
"module-resolver",
{
"root": ["./src"],
"extensions": [".js", ".ios.js", ".android.js"],
"stripExtensions" : [".ios.js", ".android.js"]
}
] |
With the help of @MatthieuLemoine, we finally landed a new version which hopefully should finally fix the issue for React Native. So please use Please read this to see how to setup for React Native: https://github.com/tleunen/babel-plugin-module-resolver#usage-with-react-native Thank you. |
I would suggest using this with React Native: |
@dclipca so you suggesting not to use this babel plugin for RN apps at all? |
This module does not seem to work with React Native Platform extensions
import foo from 'components/foo'
where foo is one of
foo.android.js
orfoo.ios.js
Works fine if i drop the android/ios part of the extension or if I fully specify
./components/foo
babelrc:
The text was updated successfully, but these errors were encountered: