2

I'm bizarrely getting an error that a local file import can't be resolved by React Native.

Unable to resolve module `./components/MyComponent" from ".//App.js`: could not resolve `/Users/myusername/Desktop/mylibrary/components/MyComponent' as a file nor as a folder","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]},"type":"bundling_error"}" 

mylibrary/App.js:

import React from 'react'; import { View, Text, StyleSheet, ScrollView, AsyncStorage, } from 'react-native'; import MyComponent from './components/MyComponent'; 

mylibrary/components/MyComponent.jsx:

import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; export default class MyComponent extends React.Component { render() { <View> {this.props.children} </View> } } 

I tried renaming the file to be lowercase (mycomponent.jsx), and it didn't make a difference. I also tried restarting my simulator and resetting the cache, and it also didn't help.

1
  • If I'm not mistaken the import statement by default try to import .js files, try renaming MyComponent.jsx to MyComponent.js Commented Jan 22, 2018 at 0:49

2 Answers 2

2

The import statement by default try to import .js files, try renaming MyComponent.jsx to MyComponent.js.

Quoting the MDN:

The module to import from. This is often a relative or absolute path name to the .js file containing the module, excluding the .js extension. Certain bundlers may permit or require the use of the extension; check your environment. Only single quotes and double quotes Strings are allowed.

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately that doesn't work either. :( Error becomes Unable to resolve module './components/mycomponent.js' from ".//App.js': could not resolve /Users/myusername/Desktop/mylibrary/components/mycomponent' as a file nor as a folder","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]},"type":"bundling_error"}"
@zahabba You changed the filename to lowercase? Make sure the filename case match the one you're trying to import.
1

The component is wrong. You are not returning anything in the render method. Try this:

render() { return( <View> {this.props.children} </View> ) } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.