Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
importing throws error unless index is specified #12539
This is weird...
I have a file
In this case I should be able to do either
However I get the following error unless I import the path
Versions installed, osx siera, node v7.5.0:
This is the first I have ever come across having to specify
After trying system reboot etc I also tried importing the file both ways under two variable names so I could see what is being returned:
AppImport1 (the failing import)
AppImport2 (correct but requires full path which you should never need in node ie.
Also tried a class in the
This issue is a little bit confusing, can you post an example project that repros it?
This works exactly as expected. I imagine you probably forgot to add the function wrapper around the second param in AppRegistry.registerComponent, so it invoked the functional component and returned the result, which is the result of rendering, rather than the component itself.
Feel free to create a new issue with a minimal example project that clearly demonstrates the problem if this isn't it :)
@brentvatne nope did not forget function wrapper.
The project started via
As stated unless the full index path used the default isn't imported instead it is an object instead of the expected component
If I inspect what is imported using
The entire point of this issue is the fact that it should work not that my syntax is incorrect, I would not post it before investigating. The file app/index file works fine when imported via full path, as we all know in node you should not need the full path to an index file.
It also made no difference if the exported default was a function or a class, it also made no difference if I instead imported a explicitly named component rather than default.
I intentionally only touched the two files mentioned everything else in the project is what is generated via
In addition no other node project or web react project has this import issue.
I would not be surprised if it does work fine for you... That is my point... it makes no sense why it is not working, I had no issues last time I used react-native. I have tried basic stuff I can think of, updating react-native, yarn, node, I've kept it incredibly simple so nothing else could be influencing it.
I've restarted my machine and then run nothing but terminal, my ide (atom) and the react-native commands but still nothing changes it simply won't import a perfectly valid es6 file default unless the full index path is specified.
Heres a temp repo (tho the code for the two files have been posted here anyway) https://github.com/rhysburnie/TempBugReportSetup
Further to this - if I copy the
Then after the subfolder path working I tried renaming the
So it seems like the combination of the folder name
both files exactly the same
If you have a file
What actually happens is the system is importing the root level
So while this isn't a bug it is perhaps a gotcha?
It seems reasonable to expect that some developers may create an
The gotcha is that the system prefers
referenced this issue
Feb 27, 2017
For me this was resolved months ago - just use another filename "entry.js"
It's hard to say what the app.json file is for (that is to say I don't care enough to find out), last time I opened it (a year ago) it seemed to contain redundant information that is present in the package.json anyway. However as per @ujwal-setlur comment RE deleting the file affecting ios and not android I'm guessing it may be required by apple and perhaps the name "app.json" is also required?
Seems simpler to just use another name for your entry point. A heads up in the docs would avoid future confusion.