Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
How to have a custom element be defined on npm install

I wanted to try and use a custom web component I made using vanilla javascript with npm. So I published it to npm to import it into another learning thing I am working on. My problem was that my environment didn't recognize the custom element.

My package.json defined main to be the 'index.js' file. The file defined the component using the standard customElements.define. This element didn't seem to be registered when I wanted to use it.

My current hack workaround is

class CustomElement { ... }
function defineCustomElement() { 
  customElements.define('tag-name', CustomElement)
}
export default defineCustomElement

This feels like a horrible hack though. When I search around, I don't see my problem mentioned and I can't manage to find any good information, so I'm probably missing something on what I should be searching for/looking at.

My goal would be that by just defining the component as a dependency in package.json it would automatically be defined.

Could someone please help?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda