importing throws error unless index is specified
See original GitHub issueHi,
This is weird…
I have a file app/index.js
with:
import React from 'react';
import { View, Text } from 'react-native';
export const App = () => (
<View>
<Text>The App</Text>
</View>
);
export default App;
In this case I should be able to do either import App from './app'
or import { App } from './app'
and use it in my AppRegistry.registerComponent
.
However I get the following error unless I import the path ./app/index
which you should not need to do.
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object
Versions installed, osx siera, node v7.5.0:
react-native-cli: 2.0.1
react-native: 0.41.2
This is the first I have ever come across having to specify index
is this a known issue?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:10
Top Results From Across the Web
Error when styling React components imported from index file ...
If I import the component directly from the source file I do not get the error. It only happens when I try to...
Read more >Import - Oracle Help Center
2. Import. This chapter describes how to use the Import utility, which reads an export file into an Oracle database. Import reads only...
Read more >Getting 'Invalid Index' error in Projectwise Import Tool
I'm trying to import an excel sheet file using the PW import tool but during the second step I'm getting 'Invalid Index' error...
Read more >import - JavaScript - MDN Web Docs - Mozilla
js file containing the module. In Node, extension-less imports often refer to packages in node_modules . Certain bundlers may permit importing ...
Read more >How to use an ES6 import in Node.js? - GeeksforGeeks
If we try to use import for importing modules directly in node js it will throw out the error. For example, if we...
Read more >
Top Related Medium Post
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@brentvatne FYI - Figured out what was happening…
If you have a file
./app/index.js
and you attempt to import like so:import Something from './app';
What actually happens is the system is importing the root level
./app.json
file which contains the object in question.So while this isn’t a bug it is perhaps a gotcha?
It seems reasonable to expect that some developers may create an
app
folder and that they may create anindex.js
in that folder and expect it to import as expected.The gotcha is that the system prefers
./app.json
over./app/index.js
Got burned by this as well 😃. Interestingly, it worked fine on android, but gave problems on ios. I just deleted app.json. Is it actually needed?