'I am getting a Web3 error when I try and connect MetaMask

I hired a dev to work on a smart contract and MetaMask integration, and he is no longer available for help, and now Im getting an error. The local code was working great, but now Im getting the following error in the console when I try and launch MetaMask from my site. The thing is, I get that error on a first click and nothing happens, if I click again, it fires up and starts working. Any ideas how I can fix this?

Uncaught (in promise) ReferenceError: Web3 is not defined
    at Object.approveWeb3 (map.js:248:41)
    at doNFTWorker (map.js:489:25)

I believe the issue (map.js:248:41) is in the following code:

approveWeb3: async function(){

    console.log('Approve');

    if (window.ethereum) {
        window.web3 = new Web3(window.ethereum);
        try {
            ethereum.enable();
        } catch (error) {
            console.log("user rejected permission");
        }
    } else if (window.web3) {
        window.web3 = new Web3(window.web3.currentProvider);
    } else {

        alert("No Ethereum browser detected");
    }

},


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source