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

143
Vistas
Working Vue 3 app empties mounted element when using Vue as an npm package

I'm working with a very simple Vue 3 app, listed below.

This works like a charm when including Vue as a script, see code snippet.

I need to use it with webpack however, and therefore include it as an npm package. In this case the app loads, but Vue empties everything inside the div it's mounted on. See CodeSandbox example

I've tried different ways to export and import the App object, but none work. What am I overlooking?

const {ref} = Vue;

const App = {
  setup() {
    const count = ref(0);
    const inc = () => {
      count.value++;
    };

    return {count, inc};
  }
}

Vue.createApp(App).mount('#simple-example')
<head>
  <script src="https://unpkg.com/vue@3.2.29/dist/vue.global.prod.js"></script>
</head>

<body>
  <div id="simple-example">
    <h1>Hello Vue 3!</h1>
    <button @click="inc">Clicked {{ count }} times.</button>
  </div>
</body>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Changing this:

import { createApp } from "vue";

into this:

import { createApp } from "vue/dist/vue.esm-bundler";

fixed the problem. Thanks to Estus Flask

UPDATE

The fix can be further improved by creating an alias for vue in the webpack config file:

resolve: {
    alias: {
        vue: "vue/dist/vue.esm-bundler.js"
    }
}

That will make it possible to use "vue" again in the import statement, which then points to the vue.esm-bundler.js instead of the default vue.runtime.es.js.

about 4 years ago · Juan Pablo Isaza Denunciar
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