In react-native 0.14, we can require an image using const fireImage = require('./images/demo.jpg'). The require works fine with images(png, jpeg, gif), 'js' and 'json' files.
My question is: Is it possible to 'require' a '.mp3' or '.mp4' files?
I have tried the 'mp3' file and the Xcode reported a build error like this
uncaught error Error: UnableToResolveError: Unable to resolve module ./music/some from /Users/rongshen/tmp/react-native-test/imageTest/index.ios.js: Invalid directory /Users/rongshen/tmp/react-native-test/imageTest/music/some.mp3
For anyone else running across this post that's still trying to figure it out, you can utilize the rn-cli.config.js file to add additional file types for the require() method.
Example, add a file named rn-cli.config.js to the project root with the following contents:
module.exports = {
getAssetExts() {
return ['mp3', 'mp4']
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With