Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Exported functions are not defined. Parcel/Browserify

When I use a bundler to make my JS browser compatible my exported functions are not exported.

Error: (index):11 Uncaught TypeError: connect is not a function at HTMLButtonElement.onclick ((index):11:46)

index.js (Same root file as index.html)

const {ethers} = require("ethers");

async function connect() {
    if (typeof window.ethereum !== 'undefined') {
        await ethereum.request({method: "eth_requestAccounts"});
      }
  }

  module.exports = {
    connect
  }

index.html (Same root file as index.js)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HTML 5 Boilerplate</title>
    <script src="./index.js" type="module"></script>  
  </head>
  <body>
    <button id="connect" onclick="connect()">   Connect  </button>

  </body>

</html>

Using parcel, which auto creates a dist file and starts a local server. Also tried browserify and had same issue.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parcel supports script tag/elements of type module.

This code works for me but window.ethereum is undefined, it's related to MetaMask no?

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>HTML 5 Boilerplate</title>
  </head>
  <body>
    <button id="connect">Connect</button>

    <script type="module">
      //Import your module
      import something from "./index.js";

      //Assign event listener to button
      document
        .getElementById("connect")
        .addEventListener("click", function (event) {
          something.connect();
        });
      console.log("something", something);
      /* JavaScript module code here */
    </script>
  </body>
</html>

index.js

const { ethers } = require("ethers");

async function connect() {
  console.log("Inside connect function");
  console.log("window.etherum", window.ethereum);
  console.log("ethers", ethers);
  if (typeof window.ethereum !== "undefined") {
    await ethereum.request({ method: "eth_requestAccounts" });
  }
}

module.exports = {
  connect,
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!