Type error: Property 'token' does not exist on type 'typeof Web3API'

Hi all,
I am now working on my project using typescript, nextjs and moralis. Everything is working fine until I compile the project.

My code is farley simple like below:

const getTokenInfo = async () => {
        let addr = selectedTokenRef.current!.value
        if (addr != ""){
                const options: MoralisGetTokenMetadataOptionType = { chain: "bsc testnet", addresses: [addr.toLowerCase()] };
                const tokenMetadata = await Moralis.Web3API.token.getTokenMetadata(options);
                let balance = await getTokenBalance(tokenMetadata[0].address)
                let metadata = {...tokenMetadata[0], balance: balance}
        } else {
            alert("Input token address")

when doing build process, It shows below error msg to me:

> next build

info  - Loaded env from /Users/macbookpro4eric/Projects/blockchain/project32_safetrate_ts/.env
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
Failed to compile.

Type error: Unexpected keyword or identifier.

  1591 |   }
  1592 | 
> 1593 |   static eth-defi: {
       |          ^
  1594 |     getPairReserves: (options: operations["getPairReserves"]["parameters"]["query"] & operations["getPairReserves"]["parameters"]["path"]) => Promise<operations["getPairReserves"]["responses"]["200"]["content"]["application/json"]>;
  1595 |     getPairAddress: (options: operations["getPairAddress"]["parameters"]["query"] & operations["getPairAddress"]["parameters"]["path"]) => Promise<operations["getPairAddress"]["responses"]["200"]["content"]["application/json"]>;
  1596 |   }
info  - Checking validity of types .npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/macbookpro4eric/.npm/_logs/2021-10-05T07_13_08_133Z-debug.log

I also tried to deploy the application onto vercel. And it also shows similar error like below:

info  - Checking validity of types...
Failed to compile.
Type error: Property 'token' does not exist on type 'typeof Web3API'.
e[0m e[90m 80 | e[39m            e[36mtrye[39m{e[0m
e[0m e[90m 81 | e[39m       

It will be very appreciated if anybody could give me a hint about where do I do wrong.

Hey @happyeric77

Can you provide a link to the repository?

Hi Yomoo,
Thanks for your reply. I cannot provide the repo here publicly since it is built for my customer. I can grant you access to my repo if it is possible for you to let me know username or email of the github

Hi Yomoo, Thanks for sharing. I have made you able to access the private repo already. All the config files are already included. I will be ready to run “npm run dev” for the test server and “npm run build” to build (it will fail) after “npm install”.

1 Like

Fix will be pushed soon. I’ll let you know

1 Like

Hey @happyeric77

Update moralis version to 0.0.69