Expensify / react-native-qrcode-svg

A QR Code generator for React Native based on react-native-svg and node-qrcode.
MIT License
1.07k stars 217 forks source link

Property 'TextEncoder' doesn't exist #199

Closed syuanlj closed 3 months ago

syuanlj commented 3 months ago

image

ashindiano commented 3 months ago

I am facing the same issue too

ZaurRza commented 3 months ago

same error

farm16 commented 3 months ago

@syuanlj same here, but can you provide more info regarding which version you are using. also the output of npx react-native info can help

osamaabdalla commented 3 months ago

This solution worked for me:

  1. First, install the text-encoding package by running the following command:

    npm install --save text-encoding
  2. Then, import it into the file where you are using the QRCode:

    import 'text-encoding';

this is influenced by: https://github.com/facebook/hermes/issues/948#issuecomment-1484240071

12ya commented 3 months ago

created a pull request. who can't wait for merge just change this in package.json "react-native-qrcode-svg": "https://github.com/12ya/react-native-qrcode-svg"

syuanlj commented 3 months ago

This solution worked for me:

  1. First, install the text-encoding package by running the following command:
    npm install --save text-encoding
  2. Then, import it into the file where you are using the QRCode:
    import 'text-encoding';

this is influenced by: facebook/hermes#948 (comment)

urvindevstree commented 3 months ago

This solution worked for me:

Navigate to _nodemodule/qrcode/lib/core/byte-data.js file.

  1. Please update below line : this.data = new TextEncoder().encode(data) to this.data = stringToUtf8Uint8Array(data).

  2. Add this function in same file :

    function stringToUtf8Uint8Array(str) {
    const utf8 = encodeURIComponent(str)
    .replace(/%([0-9A-F]{2})/g, (_, p1) => String.fromCharCode('utf-8'));
    const arr = new Uint8Array(utf8.length);
    for (let i = 0; i < utf8.length; i++) {
    arr[i] = utf8.charCodeAt(i);
    }
    return arr;
    }