fast-text-encoding icon indicating copy to clipboard operation
fast-text-encoding copied to clipboard

React Native - Android Studio - @azure/service-bus - fast-text-encoding: TypeError: Cannot read property 'prototype' of undefined

Open Giuseppe-Lo-Re opened this issue 1 year ago • 3 comments

Hi, I'm creating an android app, with a qrcode reader + form that submit on azure service-bus I installed fast-text-encoding and i have this error: TypeError: Cannot read property 'prototype' of undefined.

  1. npm install fast-text-encoding buffer process
  2. Create a file named globals.js at the root of your project or an directory:
global.TextEncoder = require('fast-text-encoding').TextEncoder;
global.TextDecoder = require('fast-text-encoding').TextDecoder;
  1. Import the globals.js import './globals';
  2. Update my form
import React, { useEffect, useState } from 'react';
import { View, Text, TouchableOpacity, Image } from 'react-native';
import { useForm } from 'react-hook-form';
import { ServiceBusClient } from '@azure/service-bus';
import CustomButton from '../../../../common/components/CustomButton/custom-button';
import CustomTextInput from '../../../../common/components/CustomButton/CustomTextInput/CustomTextInput';
import { styles } from './styles';

const connectionString = "*hidden*";
const topicName = "*hidden*";

const Form = ({ onClose }) => {
    const [sending, setSending] = useState(false);
    const defaultValues = {
        firstName: '',
        lastName: '',
        description: '',
    };

    const { control, handleSubmit, formState: { errors }, reset } = useForm({
        defaultValues,
    });

    const sendMessage = async (data) => {
        setSending(true);

        const sbClient = new ServiceBusClient(connectionString, {
            webSocketOptions: {
                webSocket: WebSocketWrapper,
            },
        });
        const sender = sbClient.createSender(topicName);

        try {
            const message = {
                body: JSON.stringify(data),
                applicationProperties: { device: 1 },
            };
            console.log("Message to be sent:", message);
            await sender.sendMessages(message);
            console.log("Message sent successfully.");
            await sender.close();
        } catch (error) {
            console.error(error);
        } finally {
            await sbClient.close();
            setSending(false);
        }
    };

    const onSubmit = (data) => {
        sendMessage(data).catch(error => {
            console.error("Submit error:", error);
        });
    };

    useEffect(() => {
        reset(defaultValues);
    }, []);

    return (
        <View style={styles.container}>
            <TouchableOpacity style={styles.closeButton} onPress={onClose}>
                <View style={styles.circle}>
                    <Text style={styles.cross}>X</Text>
                </View>
            </TouchableOpacity>
            <View style={styles.logoContainer}>
                <Image
                    source={require('../../../../public/logo.png')}
                    style={styles.logo}
                />
            </View>
            <CustomTextInput
                control={control}
                name="firstName"
                rules={{ required: true }}
                error={errors.firstName}
                errorMessage="First name is required"
                placeholder="First name"
                style={styles.input}
            />
            <CustomTextInput
                control={control}
                name="lastName"
                rules={{ required: true }}
                error={errors.lastName}
                errorMessage="Last name is required"
                placeholder="Last name"
                style={styles.input}
            />
            <CustomTextInput
                control={control}
                name="description"
                rules={{ required: true }}
                error={errors.description}
                errorMessage="Description is required"
                placeholder="Description"
                multiline={true}
                numberOfLines={10}
                style={[styles.input, styles.textArea]}
            />
            <View style={styles.buttonWrapper}>
                <CustomButton
                    title={sending ? "Sending..." : "Submit"}
                    disabled={sending}
                    buttonStyle={styles.button}
                    textStyle={styles.buttonText}
                    onPress={handleSubmit(onSubmit)}
                />
            </View>
        </View>
    );
};

export default Form;

at this link you can read the issues history. I hope you can help me solve

Regards, Giuseppe Lo Re

Giuseppe-Lo-Re avatar Jul 16 '24 15:07 Giuseppe-Lo-Re

I have the same question. Is there any progress? Thank you.

SliverYuki avatar Oct 09 '24 01:10 SliverYuki

TypeError: Cannot read property 'prototype' of undefined [Component Stack]

+1 same here

jordankkk avatar Jan 14 '25 17:01 jordankkk

I same issue here

Mochamad-Rizky avatar Jan 25 '25 13:01 Mochamad-Rizky