Unable to get mp3 file as require function of node.js.

Asked 2 years ago, Updated 2 years ago, 125 views

We are creating a sound effect playback app with Expo (React Native).

 

I'm trying to make it by referring to the Expo official document, but here, I'm importing the mp3 file as a require function.

 

Code for the Expo official document. (https://docs.expo.io/versions/latest/sdk/audio/)

const soundObject = new Audio.Sound();
try {
  await soundObject.loadAsync(require('./assets/sounds/hello.mp3'));
  await soundObject.playAsync();
  // // Your sound is playing!
} } catch (error) {
}

 

It's my code.

var testPng = require('./assets/test.png')
var testMp3 = require('./assets/test.mp3')
console.log(testPng)
console.log(testMp3)

 

Unable to resolve "./assets/test.mp3" from "App.js"

undefined Unable to resolve module ./assets/test.mp3 from App.js:

None of these files exist:

 

node.js react-native javascript

2022-09-20 21:55

1 Answers

It was resolved by reinstalling node.js with the latest version.


2022-09-20 21:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.