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

Property 'TextEncoder' doesn't exist #199

Closed
syuanlj opened this issue Aug 9, 2024 · 8 comments
Closed

Property 'TextEncoder' doesn't exist #199

syuanlj opened this issue Aug 9, 2024 · 8 comments

Comments

@syuanlj
Copy link

syuanlj commented Aug 9, 2024

image

@ashindiano
Copy link

I am facing the same issue too

@ZaurRza
Copy link

ZaurRza commented Aug 9, 2024

same error

@farm16
Copy link

farm16 commented Aug 10, 2024

@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
Copy link

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)

12ya added a commit to 12ya/react-native-qrcode-svg that referenced this issue Aug 12, 2024
@12ya
Copy link
Contributor

12ya commented Aug 12, 2024

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 syuanlj closed this as completed Aug 12, 2024
@syuanlj syuanlj reopened this Aug 12, 2024
@syuanlj
Copy link
Author

syuanlj commented Aug 12, 2024

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)

@syuanlj syuanlj closed this as completed Aug 12, 2024
@urvindevstree
Copy link

This solution worked for me:

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).

  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;
}

@arnoldosilva
Copy link

this works for me

add transformer on metro:

const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

const config = {
transformer: {
babelTransformerPath: require.resolve("react-native-qrcode-svg/textEncodingTransformation"),
},
};

module.exports = mergeConfig(defaultConfig, config);

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

8 participants