solana-labs / solana-program-library

A collection of Solana programs maintained by Solana Labs
https://solanalabs.com
Apache License 2.0
3.5k stars 2.04k forks source link

React Native error: No identifiers allowed directly after numeric literal #3574

Closed syed-dce closed 1 year ago

syed-dce commented 2 years ago

In react native I am getting this error : [SyntaxError: No identifiers allowed directly after numeric literal]

There is no stack shown. How do I even begin debugging this without any call stack?

Error message image

Here is my App.tsx file. When I comment out getOrCreateAssociatedTokenAccount line the error goes away. When I uncomment getOrCreateAssociatedTokenAccount line the error comes back

Also, importantly this same code works successfully in nodejs separately (that is when I make a separate node app) - but fails when it (code) is being used in react-native using the same library - @solana/spl-token.

App.tsx (react-native):-

import * as web3 from '@solana/web3.js';
import * as spl  from "@solana/spl-token";
import React, {useRef} from 'react';
import {SafeAreaView, ScrollView, StatusBar, Text, TouchableOpacity} from 'react-native';

export const App = () => {
  const scrollViewRef = useRef<null | ScrollView>(null);

  const onPress = async() => {

    console.log("=============== inside press function ============")
    const connectionCluster = new web3.Connection(web3.clusterApiUrl('devnet'));

    let myAppWalletSecretKey = new  Uint8Array([63,187,34,85,159,44,110,254,116,129,35,146,244,255,155,211,149,242,54,58,203,80,192,19,201,245,83,120,199,209,45,200,244,225,78,38,107,204,74,92,219,98,200,117,166,582,120,165,111,161,190,47,129,123,66,42,89,147,160,212,184,123,133,213]) 

    const TokenAddress = new web3.PublicKey("8hhtxFeTfwjxM6E5CCMyAwAD2FyYPhFltkw7NG1kCXcD");        // address of the token
    const recipientAddress = new web3.PublicKey("Dd77w197tyyst5wXYXUHVabWBYyWbTdBzHecpqLD6z16");    // address of person who is receiving
    const senderKeypair = web3.Keypair.fromSecretKey(myAppWalletSecretKey);     // account of the person who is sending

    // When I comment out below line the error goes away. 
    // When I uncomment below line the error comes back
    const addRecipientToAcct = await spl.getOrCreateAssociatedTokenAccount(
      connectionCluster,
      senderKeypair,
      TokenAddress,
      recipientAddress
    );
  }

  return (
    <>
      <SafeAreaView>
          <TouchableOpacity
            style={{backgroundColor: 'red'}}
            onPress={onPress}
          >
              <Text>Press Here</Text>
          </TouchableOpacity>
      </SafeAreaView>
    </>
  );
};

export default App;

package.json (react-native):

{
  "name": "testsolana",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
  },
  "dependencies": {
    "@solana/spl-token": "0.3.0",
    "@solana/web3.js": "1.41.3",
    "metro-config": "0.70.1",
    "react": "17.0.2",
    "react-native": "0.68.1",
    "react-native-get-random-values": "1.7.2",
    "react-native-url-polyfill": "1.3.0",
    "text-encoding": "0.7.0",
    "text-encoding-polyfill": "0.6.7"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "@testing-library/jest-native": "^4.0.4",
    "@testing-library/react-native": "^9.1.0",
    "@types/jest": "^26.0.23",
    "@types/react-native": "^0.67.3",
    "@types/react-test-renderer": "^17.0.1",
    "@typescript-eslint/eslint-plugin": "^5.17.0",
    "@typescript-eslint/parser": "^5.17.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.67.0",
    "react-test-renderer": "17.0.2",
    "typescript": "^4.4.4"
  },
  "resolutions": {
    "@types/react": "^17"
  },
  "jest": {
    "preset": "react-native",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ]
  }
}
syed-dce commented 2 years ago

I noticed it comes from @solana/buffer-layout-utils

anvog777 commented 2 years ago

@syed-dce Did you solve it? I am having the same issue. Thanks!

masnasri-a commented 2 years ago

i am have same problem

anvog777 commented 2 years ago

I solved it by upgrading to React-Native 0.7

masnasri-a commented 2 years ago

oh thank you so much, ill try to upgrade, btw are u running with expo?

anvog777 commented 2 years ago

No, I am not using Expo.

I was using a lot of libraries in my project, and four of them gave me compatibility problems with React 0.7. I had to solve the problem with each one before it works.

masnasri-a commented 2 years ago

Ty btw, but i have new problem at cant find variable BigInt after upgrading react native