React-Typescript unable to import video file

2 weeks ago 8
ARTICLE AD BOX

I'm trying to import an mp4 file for embedding on my website, but I get an error when I try to import it.

Cannot find module '../assets/robotShowcase.mp4' or its corresponding type declarations.

This is despite being able to import image and svg files.

While googling, I found a post with a similar question where the problem was solved by moving the file to the public folder in the root folder of the project, but after trying it, I got the same error.

Here's some example code:

import React from 'react'; import Worm from '../assets/Worm.png' import Logo from '../assets/logo.svg' import RobotShowcase from '../assets/robotShowcase.mp4'; //Error function Home() { return ( <div> <img src={Logo} /> <img src={Worm}></img> <video> <source src={RobotShowcase} type='video/mp4' /> Your browser does not support the video tag. </video> </div> ); } export default Home;

Lucy's user avatar

1

Read Entire Article