Home > Net >  How to import mp3 file in TypeScript?
How to import mp3 file in TypeScript?

Time:09-06

I'm working on a web app using React and TypeScript. Right now, I'm trying to import mp3 file to use for use-sound, but the TypeScript gives me:
"Cannot find module '../../assets/sounds/sample1.mp3' or its corresponding type declarations.ts(2307)"
Anyone knows how to fix this? In below, I have the code from the use-sound document to describe my issue.

import useSound from 'use-sound';
import s1 from '../../assets/sounds/sample1.mp3'; // <- this gives me the error

const BoopButton = () => {
  const [play] = useSound(s1);

  return <button onClick={play}>Boop!</button>;
};

CodePudding user response:

Did you add types for this? Try npm install @types/use-sound

  • Related