Hi everyone,
I am getting the error Unable to resolve “./registerRootComponent.mjs” from “AppEntry.js” when I try to build my Expo app for iOS.
I have checked the following things:
The file registerRootComponent.mjs is in the same directory as the file AppEntry.js.
The file registerRootComponent.mjs is a valid JavaScript file.
The file registerRootComponent.mjs is imported correctly in the file AppEntry.js.
The file registerRootComponent.mjs is not hidden.
The file registerRootComponent.mjs is not read-only.
I am not sure what else to check. Can anyone help me?
My AppEntry.js
import registerRootComponent from './registerRootComponent.mjs';
registerRootComponent(App);
class App extends React.Component {
render() {
return (
<View style={{ flex: 1 }}>
<Text>Hello, world!</Text>
</View>
);
}
}
My App,js
import React, { useState, useEffect, useRef, useCallback, useMemo } from 'react';
import { BluetoothSerial, Device, FlatList, Text, TextInput, Button } from 'react-native-bluetooth-serial';
const App = () => {
const [devices, setDevices] = useState([]);
const [selectedDevice, setSelectedDevice] = useState(null);
const [message, setMessage] = useState('');
const bleManager = new BluetoothSerial();
useEffect(() => {
bleManager.startScan(null, null, (error, device) => {
if (error) {
console.error(error);
} else {
setDevices((devices) => [...devices, device]);
}
});
}, []);
const handleDeviceSelect = (device) => {
setSelectedDevice(device);
bleManager.stopScan();
};
const handleSendMessage = async () => {
if (!selectedDevice) {
return;
}
const characteristic = await selectedDevice.getCharacteristic('B3B2BA57-8563-C50C-AD50-5AAA8564CD2D');
if (!characteristic) {
return;
}
await characteristic.writeValue(message);
};
const renderDevice = ({ item }) => {
return (
<Button title={item.name || item.id} onPress={() => handleDeviceSelect(item)} />
);
};
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={{ padding: 16 }}>
<Text>BLE Device Scanner</Text>
<FlatList
data={devices}
keyExtractor={(item) => item.id}
renderItem={renderDevice}
/>
{selectedDevice && (
<>
<TextInput
value={message}
onChangeText={(text) => setMessage(text)}
placeholder="Enter message"
/>
<Button title="Send" disabled={!selectedDevice} onPress={async () => {
const characteristic = await selectedDevice.getCharacteristic('B3B2BA57-8563-C50C-AD50-5AAA8564CD2D');
if (!characteristic) {
return;
}
await characteristic.writeValue(message);
}} />
</>
)}
</View>
</SafeAreaView>
);
};
export default App;
Thanks,