Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find module React Native #122

Open
RFlintstone opened this issue Jun 29, 2021 · 0 comments
Open

Can't find module React Native #122

RFlintstone opened this issue Jun 29, 2021 · 0 comments

Comments

@RFlintstone
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant