-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Incorrect resolve js file as directory #2825
Comments
@martinbigio Any ideas? |
I believe the problem is that you cannot traverse up from the packager root. Whether this is desirable or not I am not sure... |
Actually, I work on a demo project and want to show people that we can use most of same flux (redux) code and different components files to build app for DOM(web and desktop apps which using electron), iOS, android and terminal (using react-blessed) at the same time. So I reuse almost the same code as my ios-android demo, but moved src to the parent folder. |
I already have some successful attempts on DOM and terminal, but this approach break the react-native by this issue. |
From reading the react-native packager documentation, it seems like you may be able to specify an extra To do this, you would edit the Then you will need to manually run the packager via I am not sure exactly what your require path would need to look like for this. Possibly: It is entirely possible that this will run into some other issues with resolving the dependencies because the relative path does not match reality. This is an issue in my project because we are using Typescript which is perfectly happy to traverse up the file system to find other modules, but it chokes on the 'fake' relative path that would be needed here. |
Yup, if you're running the packager from within You can easily debug this by looking at the packager logs, it prints:
It's only possible to require files that are under that path. You might be able run the packager from the top-level directory though by passing it the root (haven't tried this, please let us know if that works). |
@mkonicek I've try to set And there is my script use to launch application: //start.js
var spawn = require('child_process').spawn;
var path = require('path');
spawn('sh', [
path.resolve(__dirname, 'node_modules/react-native/packager', 'packager.sh'),
'--projectRoots',
process.cwd(),
'--root',
path.resolve(__dirname, '../'), //up to parent
], {stdio: 'inherit'}); Is it a babel transformer problem? Now I can't find the reason or solution for it. Any idea? Looking forward to your reply. @brentvatne I think maybe traverse up from the packager root is desirable. For the reason of my team development progress, we have use two versions RN to our project: v0.10 to iOS and v0.14 to Android. So we have to keep two project for each other. And now I want to use some common files which should saved at parent path. Just like:
So maybe we need to consider how to implement it. Any advice or discuss about it? 😄 |
+1 I had the same issue. What I did was re-factor/re-arrange my folder structure, so that it'll work 😢 |
It's not possible to traverse outside the default project root or the additional roots you specify as we need to cache a lot of the file system information to make the queries to the packager performant enough. In regards to the |
I'll close the issue as we don't plan supporting being able to require files that are not included on the roots. Please re-open if you don't agree :) |
@martinbigio which folder structure you will suggest for a project that contains mobile and also web? |
how about @mc-zone proposal? I think he was running into an error just because the plugin |
@martinbigio Yes, but not all. I've fall into a trap dug myself. As I mentioned above. I ran packager at my iOS project folder(v0.10, not support So maybe something was wrong with dependences resolve when traverse outside the root. And I've know it's not support on this way. I didn't continue to track it. Currently, I've already achieve it through a workflow by self: write once at a folder, watch changed files and copy to each project (use Gulp temporarily). And I also think it is cool if we can support it. Anyway, thank you for your reminder. |
@mc-zone could you share your configuration in case anyone else runs into this same issue? It's funny that at the moment I'm writing this answer the proposed watchman solution is #1 on product pains (https://productpains.com/post/react-native/symlink-support-for-packager/) Anyways just wanted to flag this this for you :) |
I disagree with this being closed. The reason is simple. I have a react native app and web app in the same project. I would like to have the folder structure be: 'app' 'web' 'shared' This way I can put redux, and other shared logic between the apps in one place instead of copy and pasting. I don't see an easy way to do this currently? |
I agree with zackify. It seems like a very common structure to have something along the lines of:
Whatever the solution, I think it really needs to be compatible with IDE autocomplete. flow, lint, etc. A (minor) problem with creating symlinks for the |
check out this: #12241 Hope this helps... |
In my project, I have directories structure like below:
And I require
App.js
in myindex.ios.js
:I get a warning:
I thought we should not hide detail information about a happened error here:
Anyway, I add a
console.error(error)
for this, and see following error message print out:Why
require('../src/containers/App')
will try to resolve a directory there? I expected it should resolve../src/containers/App.js
.The text was updated successfully, but these errors were encountered: