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

153
Vistas
Javascript: How to init Audio file with variable

I am trying to play an audio file which will be set using a variable. I can set the path just fine when hardcoding the string - but not when using the variable.

    var path = "../../recordings/test.mp3"
    this.audio = new Audio(require('../../recordings/test.mp3')) // <- This line is fine
    this.audio = new Audio(require(path)) // <- This line gives the following error:

When using a path string I receive the following error:

Error: Cannot find module '../../recordings/test.mp3' at webpackEmptyContext (components sync:2) at VueComponent.playAudio (MyCarousel.vue:119) at click (MyCarousel.vue?a868:120)

Why is it that I can file the file when explicitly hardcoding the string but not when using a variable for its path?

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