title: EDIT: How to import MP3 files in React app
body: <p><strong>UPDATE
  The problem lied with my lack of knowledge in the environment I was working on but the answers given below should be useful for others with similar problems.</strong></p>
  <p>EDIT: As it seems the problem is that there's something funky going on with trying to import my mp3 to my React app/component.
  The current issues is that when I try to use:</p>
  <p><code> import soundfile from &quot;../neure-resources/test.mp3&quot;</code></p>
  <p><strong>I end up with an error of:</strong></p>
  <blockquote>
  <p>&quot;Cannot find module &quot;../neure-resources/test.mp3&quot;</p>
  </blockquote>
  <p><strong>Solving this issue for any other import of an component would be to make sure that the component that is being imported has also been defined to be exportable but how would one go about doing this to an MP3-file?</strong></p>
  <hr />
  <p>So to start with I'm not sure if my problem has to do with importing/linking my mp3 file OR with how to play audio clips in React (or something else). I will edit the title once we figure out what my issue exactly is.</p>
  <p>So I have an app where I have a button on the web page that the user can push to play a mp3-file. Simple stuff but I'm running constantly into the following error:</p>
  <blockquote>
  <p>HTTP load failed with status 404. Load of media resource &quot;...&quot; failed.</p>
  </blockquote>
  <p>Now while I am not super proficient in file paths etc. I'd figure by looking at guides and examples I could figure it out, but I haven't been able to.</p>
  <p>My abbreviated file structure is something like (<strong>check bottom of post for more detailed description</strong>):</p>
  <blockquote>
  <p>student/src/components</p>
  </blockquote>
  <p>and under components I have my actual app in a folder and another folder under components where I planned to store my &quot;resources&quot; so:</p>
  <blockquote>
  <p>components/my-app-folder/my-actual-app.tsx</p>
  <p>components/my-resources/my.mp3</p>
  </blockquote>
  <p>For the filepath as I understood</p>
  <blockquote>
  <p>&quot;..&quot;</p>
  </blockquote>
  <p>signifies for the path to start from one folder above the current location which would be my</p>
  <blockquote>
  <p>&quot;/components&quot; -folder</p>
  </blockquote>
  <p>and my resources folder is under the component folder so I figured that should be fine.
  I looked up a few other SO questions about playing audio in React and found a question that suggested roughly the following:</p>
  <p>Inside my</p>
  <p><code>render()</code></p>
  <pre><code>let path = &quot;../my-resources/test.mp3&quot;;
  let audio = new Audio(path);
  </code></pre>
  <p>And then for the JSX part:</p>
  <pre><code>audioPlayer = (
              &lt;div className=&quot;count-number-equivelance-audioPlayer&quot;&gt;
                  &lt;button id=&quot;equivalence-audio-button&quot; onClick={() =&gt; audio.play()}&gt;Soundclip!&lt;/button&gt;
              &lt;/div&gt;
          ); 
  </code></pre>
  <p>I've tried:</p>
  <p><code>    let path = &quot;../my-resources/test.mp3&quot;;</code></p>
  <p>and</p>
  <p><code>    let path = &quot;../../my-resources/test.mp3&quot;;</code></p>
  <p>as I wasn't sure if one &quot;..&quot; pointed to the folder the actual app was nested in and required another &quot;..&quot; to actual point at the &quot;components&quot; folder but both of them produce the same error. I also tried using the whole path and moving the mp3 around to the same folder as the app itself but got the same result.</p>
  <p>So I am thoroughly confused as to if I just suck at using external resources in my app or is my actual code and/or knowledge of React to blame here. The error I receive would lead me to believe that the resource isn't being located properly but I'm not sure if that's just a side effect of faulty code.</p>
  <p>EDIT: I'm also working in a virtual environment, running my own stack locally if that makes some difference to the situation.</p>
  <p>Also for reference a picture of the file tree:</p>
  <p><strong>The files opened in the picture contain the app in question and the resource it's trying to use:</strong></p>
  <p><a href="https://i.stack.imgur.com/MRjr5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MRjr5.png" alt="File tree" /></a></p>
  <p>The path leading up to components is the following (pic would be really big if I tried to grab the whole path in one picture).</p>
  <blockquote>
  <p>/Users/&quot;name of user&quot;/arvio/client/student/src/components</p>
  </blockquote>