'How to fix the Cannot find module mp3 file or its corresponding type declarations

enter image description here

How to fix the error Cannot find module './audio/audio1.mp3' or its corresponding type declarations. also already use the require('./audio/audio1.mp3') and also getting an error.



Solution 1:[1]

Inside the src/react-app-env.d.ts add this:

/// <reference types="react-scripts" />
    declare module '*.mp3'; // '*.wav' if you're using wav format

Now you can use it like this:

import audio1 from './audio/audio.mp3';

const myAudio = new Audio(audio1);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1