admin管理员组文章数量:1180406
I need some help to handle local video files in reactjs... can't resolve ./assets/video.mp4 error... tried every possible direction..
the idea behind this is to make a full screen video like .asp but with Reactjs.
video.js
import React from 'react';
class Video extends React.Component {
render(){
return(
<div className="myVideo">
<video controls autostart autoPlay src={this.props.src} type={this.props.type}/>
</div>
)
}
}
export default Video;
index.js
import React,{Component} from 'react';
import ReactDOM from 'react-dom';
import Video from './video';
import Robin from './assets/Robin.mp4'
const VIDEO = {
src:Robin,
type:'video/mp4'
};
class App extends Component {
constructor(props){
super(props)
this.state = {
src: VIDEO.src,
type:VIDEO.type
}
}
render(){
return(
<div>
<Video src={this.state.src} type={this.state.type}/>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('root'));
console error:
./src/index.js Module not found: Can't resolve './assets/*.mp4' in 'C:\Users\sanjs\Desktop\landing-video\src'
I need some help to handle local video files in reactjs... can't resolve ./assets/video.mp4 error... tried every possible direction..
the idea behind this is to make a full screen video like https://www.w3schools.com/howto/howto_css_fullscreen_video.asp but with Reactjs.
video.js
import React from 'react';
class Video extends React.Component {
render(){
return(
<div className="myVideo">
<video controls autostart autoPlay src={this.props.src} type={this.props.type}/>
</div>
)
}
}
export default Video;
index.js
import React,{Component} from 'react';
import ReactDOM from 'react-dom';
import Video from './video';
import Robin from './assets/Robin.mp4'
const VIDEO = {
src:Robin,
type:'video/mp4'
};
class App extends Component {
constructor(props){
super(props)
this.state = {
src: VIDEO.src,
type:VIDEO.type
}
}
render(){
return(
<div>
<Video src={this.state.src} type={this.state.type}/>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('root'));
console error:
Share Improve this question edited Nov 5, 2021 at 19:54 Ahmet Emre Kilinc 6,88519 gold badges36 silver badges47 bronze badges asked May 4, 2019 at 4:57 Santiago Spinetto JungSantiago Spinetto Jung 1981 gold badge4 silver badges14 bronze badges 2 |./src/index.js Module not found: Can't resolve './assets/*.mp4' in 'C:\Users\sanjs\Desktop\landing-video\src'
3 Answers
Reset to default 20- Create a
custom.d.ts
in your src directory - Paste this code in that file
declare module '*.mp4' {
const src: string;
export default src;
}
That should work!
Maybe you have some spelling mistake here is a code for import local video and it just works fine
import React from "react";
import "./App.css";
import Video from "./video.mp4";
function App() {
return (
<div className="App">
<video controls autostart autoPlay src={Video} type="video/mp4" />
</div>
);
}
export default App;
I imported my video file at the same directory of app.js. Maybe this will help you.
solved! the problem was that the filename 'Robin .mp4' and I imported as ''Robin.mp4" so I changed de filename to 'Robin.mp4' and that's it.
本文标签: javascripthow to handle local video files ReactjsStack Overflow
版权声明:本文标题:javascript - how to handle local video files Reactjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738213120a2068984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
assets
a sub-folder oflanding-video/src
or a sub-folder oflanding-video
? If the latter, you may need../assets
instead of./assets
– Jaromanda X Commented May 4, 2019 at 5:58