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?