I'm having trouble exporting modules from my project folder (node modules such as 'react', 'react-native' work just fine) to my App.js file. I have created a new project using create-react-native-app and tried the following:
- Added test_file.js to my project folder.
- Inside test_file I declared variable
test
and then exported it. - I then imported it to my App.js and ran
npm start
.
Everything seems to be fine until I try running it through expo. JavaScript bundle building fails and in my phone it gives an error message: The development server returned response error code: 500
.
There is also a message: "Unable to resolve module `test_file` from `C:\Users\User\Projects\Test\App.js`: Module `test_file` does not exist in the Haste module map\n\n This might be related to to https://github.com/facebook/react-native/issues/4968\n To resolve try the following:\n 1. Clear watchman watches: `watchman watch-del-all`.\n 2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n 3. Reset Metro Bundler cache: `rm -rf /Test/metro-bundler-cache-` or `npm start -- -- reset-cache`. 4. Remove haste chache: `rm -rf /Test/haste-map-react-native-packager-`.".
So far I have tried all four methods and looked through the provided link, but haven't found a solution yet. I also tried using require
instead of import
.
What could be causing this problem?
EDIT: Here is the test code:
test_file.js:
const test = 'Hello World.';
export default test;
App.js:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import test from 'test_file';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Text>{test}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});