Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda