skip to Main Content

I’m using react native 0.72.4

I’m getting this error: Reference Error: Property 'Text Encoder' doesn't exist at multiple places in my app. I didn’t use it explicitly but my npm packages like qr-code-svg uses this package.

I don’t know what Text Encoder is or where it is used .. i don’t know why all of it occurs suddenly.

2

Answers


  1. this worked for me using same react native 0.72.4

    install text-encoding using npm install --save text-encoding --legacy-peer-deps

    then import it everywhere you have imported the qrcode like so
    import 'text-encoding';

    sample of how your code should look like when done with the install

    import QRCode from 'react-native-qrcode-svg';
    import 'text-encoding';
    

    hope this helps!

    Login or Signup to reply.
  2. This solution worked for me (https://github.com/awesomejerry/react-native-qrcode-svg/issues/199#issuecomment-2283588262):

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

    1. Please update below line :

    this.data = new TextEncoder().encode(data)

    to

    this.data = stringToUtf8Uint8Array(data).

    1. 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;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search