node.js의 require함수로 mp3파일을 가져올 수가 없습니다.

조회수 794회

엑스포(리액트네이티브)로 효과음 재생 앱을 만들고 있습니다.

 

엑스포 공식문서를 참고해서 만들려고 하는데 여기서는 mp3 파일을 require 함수로 가져오고 있습니다.

 

엑스포 공식 문서의 코드입니다. (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) {
}

 

제 코드입니다.

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:

  • test.mp3
  • assets\test.mp3\index(.native|.android.expo.ts|.native.expo.ts|.expo.ts|.android.expo.tsx|.native.expo.tsx|.expo.tsx|.android.expo.js|.native.expo.js|.expo.js|.android.expo.jsx|.native.expo.jsx|.expo.jsx|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.wasm|.native.wasm|.wasm)
  • node_modules\react-native\Libraries\Utilities\HMRClient.js:307:41 in showCompileError
  • node_modules\react-native\Libraries\Utilities\HMRClient.js:228:26 in client.on$argument_1
  • node_modules\eventemitter3\index.js:181:39 in emit
  • node_modules\metro\src\lib\bundle-modules\WebSocketHMRClient.js:80:20 in _ws.onmessage
  • node_modules\event-target-shim\dist\event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
  • node_modules\react-native\Libraries\WebSocket\WebSocket.js:232:27 in _eventEmitter.addListener$argument_1
  • node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 in emit
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0
  • [native code]:null in callFunctionReturnFlushedQueue

 

왜 png 파일은 require 함수에 인자로 들어가는데, mp3파일은 오류가 발생할까요?

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)