Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!