Skip to content

Can't find module React NativeΒ #122

@RFlintstone

Description

@RFlintstone

React native can't seem to import (or require) huejay with react native.

Boiler template (except useEffect()):

import {StatusBar} from 'expo-status-bar';
import React, {useEffect} from 'react';
import {Alert, Button, StyleSheet, Text, View} from 'react-native';

import * as huejay from 'huejay';
// let huejay = require('huejay');

export default function App() {

    useEffect(() => {
        // Alert.alert('App (re)loaded! πŸ˜„');

        huejay.discover()
            .then((bridges: any) => {
                for (let bridge of bridges) {
                    console.log(`Id: ${bridge.id}, IP: ${bridge.ip}`);
                }
            })
            .catch((error: { message: any; }) => {
                console.log(`An error occurred: ${error.message}`);
            });

    }, [])

    return (
        <View style={styles.container}>
            <Text>Open up App.tsx to start working on your app!</Text>
            <StatusBar style="auto"/>

            <Button title="Press me" onPress={() => buttonFunction()} />
        </View>
    );

    function buttonFunction() {
        Alert.alert('Simple Button pressed! πŸ˜„');
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
    },
});

(Expo) Error:

Building JavaScript bundle: error
Unable to resolve module huejay from D:\Users\rwfli\Documents\Ruben Portfolio\Philips_Hue_App\philips-hue-app\App.tsx: huejay could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  3 | import {Alert, Button, StyleSheet, Text, View} from 'react-native';
  4 |
> 5 | import * as huejay from 'huejay';
    |                          ^
  6 | // let huejay = require('huejay');
  7 |
  8 | export default function App() {

I've no idea how it doesn't seem to get the node module with a simple require / import. Is this React (Native) not working well in combination with the module?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions