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

109
Views
Las funciones exportadas no están definidas. Paquetería/navegador

Cuando uso un paquete para hacer que mi navegador JS sea compatible, mis funciones exportadas no se exportan.

Error: (índice): 11 TypeError no detectado: la conexión no es una función en HTMLButtonElement.onclick ((índice): 11:46)

index.js (el mismo archivo raíz que 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 (el mismo archivo raíz que 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>

Usando el paquete, que crea automáticamente un archivo dist e inicia un servidor local. También probé browserify y tuve el mismo problema.

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

0

Parcel admite etiquetas/elementos de secuencia de comandos de tipo módulo.

Este código funciona para mí, pero window.ethereum no está definido, está relacionado con MetaMask, ¿no?

índice.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>

índice.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!