I am trying to import the @metamask/detect-provider” library but when I go to run npm start I get the error ERR_UNKNOWN_FILE_EXTENSION.
I tried searching online for a possible solution but was unsuccessful
Source code app.js
import detectEthereumProvider from '@metamask/detect-provider';
const provider = await detectEthereumProvider();
const express = require("express");
const app = express();
if (provider) {
app.get("/", function (req, res) {
res.sendFile(__dirname + "/index.html");
});
} else {
app.get("/", function (req, res) {
res.sendFile(__dirname + "/error.html");
});
}
module.exports = app;
package.json
{
"name": "myapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"type": "module",
"dependencies": {
"@maticnetwork/maticjs": "^3.2.2",
"@maticnetwork/maticjs-web3": "^1.0.1",
"@metamask/detect-provider": "^1.2.0",
"body-parser": "^1.18.3",
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"jade": "~1.11.0",
"morgan": "~1.9.1",
"request": "^2.88.2",
"truffle": "^5.4.33",
"web3": "^1.7.0"
}
}