6

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.

asked Aug 8, 2024 at 12:04
2
  • This question is similar to: Expo React Native Can't find variable: TextDecoder. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Aug 8, 2024 at 13:48
  • Upgrading React Native to a version that includes TextEncoder will fix this. Otherwise, what's happening is you likely have something that's trying to access TextEncoder like it's in a browser. You can try exlcuding qr-code-svg from loading using Metro's blocklist if you can't remove it. Commented Feb 12, 2025 at 3:35

3 Answers 3

5

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!

answered Aug 11, 2024 at 10:03
Sign up to request clarification or add additional context in comments.

Comments

3

They have fixed this issue with version 6.3.2

Update to this version and everything should work fine.

Ref:

  1. https://github.com/grgia/react-native-qrcode-svg/issues/199
  2. https://github.com/grgia/react-native-qrcode-svg/pull/200
answered Aug 13, 2024 at 19:44

Comments

0

Package text-encoding is no longer maintained. You should install a polyfill.

npm install text-encoding-polyfill

And include it at the top of your project.

// index.js
import 'text-encoding-polyfill'
answered Feb 12, 2025 at 1:27

3 Comments

TextEncoder is included in some newer version of React Native, like 0.75 or 0.76, so this shouldn't even be needed.
Yeah... Meanwhile in the real world not everyone is running on the newest react-native version and has resources to update their whole project before the demo that is scheduled next week! :D
Okay good luck buddy.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.