sqmk / huejay

Philips Hue client for Node.js
MIT License
424 stars 40 forks source link

Can't find module React Native #122

Open RFlintstone opened 3 years ago

RFlintstone commented 3 years ago

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?