solana-labs / solana-web3.js

Solana JavaScript SDK
https://solana-labs.github.io/solana-web3.js
MIT License
2.18k stars 864 forks source link

[Bug] Error: Failed to construct 'TextDecoder': the 'fatal' option is unsupported. #1405

Closed jupiterrosen closed 1 year ago

jupiterrosen commented 1 year ago

Overview

I'm using "@solana/web3.js": "1.41.6" under react native "expo": "^46.0.17" for deeplink connection with Phantom, however, after upgrading from expo sdk 46 to expo sdk 49, the error: Error: Failed to construct 'TextDecoder': the 'fatal' option is unsupported., js engine: hermes are consistently occured when solana web3js is imported

Steps to reproduce

use this package.json for this repo(https://github.com/phantom/deep-link-demo-app/tree/nick/upgrade-to-expo-48)

{
  "name": "rosen-app",
  "version": "1.1.0",
  "scripts": {
    "start": "expo start --dev-client",
    "dev": "cross-env APP_ENV=dev npx expo start",
    "staging": "cross-env APP_ENV=staging npx expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "lint": "eslint ."
  },
  "engines": {
    "node": ">= 18.0.0"
  },
  "dependencies": {
    "@expo/config-plugins": "~7.2.2",
    "@expo/metro-config": "^0.10.6",
    "@moralisweb3/common-evm-utils": "^2.14.2",
    "@moralisweb3/common-sol-utils": "^2.14.2",
    "@pokopayment/react-native-sdk": "^0.5.1",
    "@react-native-async-storage/async-storage": "1.18.2",
    "@react-native-community/checkbox": "^0.5.12",
    "@react-native-community/netinfo": "9.3.10",
    "@react-native-masked-view/masked-view": "0.2.9",
    "@react-navigation/bottom-tabs": "6.3.1",
    "@react-navigation/native": "^6.0.11",
    "@react-navigation/stack": "^6.2.2",
    "@reduxjs/toolkit": "1.9.0",
    "@solana/web3.js": "^1.41.6",
    "@walletconnect/encoding": "^1.0.2",
    "@walletconnect/modal-react-native": "^1.0.0-rc.6",
    "awesome-only-resolves-last-promise": "^1.0.3",
    "axios": "^0.27.2",
    "big-integer": "^1.6.51",
    "borsh": "^0.7.0",
    "bs58": "^5.0.0",
    "buffer": "^6.0.3",
    "expo": "^49.0.0",
    "expo-application": "~5.3.0",
    "expo-asset": "~8.10.1",
    "expo-auth-session": "~5.0.2",
    "expo-blur": "~12.4.1",
    "expo-clipboard": "~4.3.0",
    "expo-constants": "~14.4.2",
    "expo-crypto": "~12.4.1",
    "expo-crypto-polyfills": "^1.1.0",
    "expo-dev-client": "~2.4.6",
    "expo-device": "~5.4.0",
    "expo-image-picker": "~14.3.1",
    "expo-linear-gradient": "~12.3.0",
    "expo-linking": "~5.0.2",
    "expo-localization": "~14.3.0",
    "expo-location": "~16.1.0",
    "expo-notifications": "~0.20.1",
    "expo-random": "~13.2.0",
    "expo-sensors": "~12.3.0",
    "expo-sharing": "~11.5.0",
    "expo-splash-screen": "~0.20.4",
    "expo-status-bar": "~1.6.0",
    "expo-task-manager": "~11.3.0",
    "expo-updates": "~0.18.10",
    "expo-web-browser": "~12.3.2",
    "i18next": "^22.0.4",
    "md5": "^2.3.0",
    "moment": "^2.29.4",
    "moralis": "^2.14.2",
    "patch-package": "^6.4.7",
    "prop-types": "^15.8.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-i18next": "^12.0.0",
    "react-native": "^0.72.3",
    "react-native-base64": "^0.2.1",
    "react-native-circular-progress-indicator": "^4.4.2",
    "react-native-geolocation-service": "^5.3.1",
    "react-native-gesture-handler": "~2.12.0",
    "react-native-get-random-values": "~1.8.0",
    "react-native-linear-gradient": "^2.6.2",
    "react-native-maps": "1.7.1",
    "react-native-modal": "^13.0.1",
    "react-native-popover-view": "^5.1.5",
    "react-native-reanimated": "~3.3.0",
    "react-native-reanimated-carousel": "^3.0.4",
    "react-native-recaptcha-that-works": "^1.3.2",
    "react-native-redash": "^18.1.0",
    "react-native-render-html": "^6.3.4",
    "react-native-safe-area-context": "4.6.3",
    "react-native-screens": "~3.22.0",
    "react-native-svg": "13.9.0",
    "react-native-swiper": "^1.6.0",
    "react-native-url-polyfill": "^1.3.0",
    "react-native-uuid": "^2.0.1",
    "react-native-view-shot": "3.7.0",
    "react-native-web": "~0.19.6",
    "react-native-webview": "13.2.2",
    "react-redux": "^8.0.2",
    "redux-persist": "^6.0.0",
    "tweetnacl": "^1.0.3",
    "typescript": "^5.1.3",
    "uuid": "^9.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@react-native-community/eslint-config": "^3.1.0",
    "@types/react": "~18.2.14",
    "@types/react-native": "~0.69.1",
    "cross-env": "^7.0.3",
    "eslint": "^8.21.0",
    "eslint-import-resolver-babel-module": "^5.3.1",
    "react-native-bundle-visualizer": "^3.1.1"
  },
  "overrides": {
    "react-native-webview": "13.2.2"
  },
  "private": true
}

Description of bug

Error: Failed to construct 'TextDecoder': the 'fatal' option is unsupported., js engine: hermes ERROR Invariant Violation: "main" has not been registered. This can happen if:

steveluscher commented 1 year ago

Looks like this is coming from here:

https://github.com/near/borsh-js/blob/6db74764cedb88097bd6d5636407f0b3481fba4c/borsh-ts/index.ts#L4-L8

Follow up with the Near folks and ask if they have a solution.

In the meantime, consider using one of the many text encoding polyfills for React Native, particularly one that supports the fatal option.

github-actions[bot] commented 1 year ago

Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.