The metamask.js script seems incorrect.
There isn't enough code to test but you have to do something like this
const oldProvider = web3.currentProvider; // keep a reference to metamask provider
myWeb3 = new Web3(oldProvider); // now you can use myWeb3 instead of web3
If the project is large you may want to replace web3 with myWeb3.
global.web3 = myWeb3