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

152
Visualizações
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 à 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