【问题标题】:Cant import video file Module parse failed: Unexpected character ' ' (1:0) React.js Next.js无法导入视频文件模块解析失败:意外字符“”(1:0)React.js Next.js
【发布时间】:2021-08-12 22:11:43
【问题描述】:

您好,我遇到了当前问题,我试图设置一个循环播放视频的背景,但是在从文件夹中导入 mp4 视频的那一刻,它给了我这个错误

error - ./videos/video.mp4
Module parse failed: Unexpected character ' ' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

这就是我的组件的创建方式

import React from 'react'
import styled from 'styled-components';
 import Video from '../../videos/video.mp4';

const HeroContainer = styled.div`
background: #0c0c0c;
display: flex;
justify-content: center;
align-items: center;
padding: 0 30px;
height: 800px;
position: relative;
z-index: 1;
`

const HeroBg = styled.div`
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
`
const VideoBg = styled.video`
width: 100%;
height: 100%;
-o-object-fit: cover;
object-fit: cover;
background: #232a24;
`


export default function Hero() {
  return (
    <HeroContainer>
      <HeroBg>
        <VideoBg autoPlay loop muted src={Video} type='video/mp4'/> 

      </HeroBg>
    </HeroContainer>
  )
}

我真的不知道问题可能是什么

【问题讨论】:

    标签: reactjs video module next.js


    【解决方案1】:

    你需要定义加载器来导入.mp4文件。其他文件类型也会发生这种错误。例如,我在尝试导入 .gql 文件时遇到了这个错误。要解决这个问题,你需要为特定的文件类型定义加载器。

    如果您使用的是 webpack,这可能会对您有所帮助。 How to load a local video in React using webpack?.

    附:我个人不喜欢这种设置。如果可能的话,我想说只提供一个网址。

    【讨论】:

    • 我设置成这样 pexels.com/es-es/video/…" type='video/mp4'/> 但仍然不显示视频,知道吗?
    • 嗯,您提供的链接只是显示网页。好像这不是一个正确的视频网址。
    • 我找到了当前的网址player.vimeo.com/video/433317878,但仍然无法正常工作lol
    • &lt;VideoBg.Source src={...url} type="video/mp4" /&gt;
    • 检查这里npmjs.com/package/…
    猜你喜欢
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 2019-06-03
    • 2021-03-18
    • 2019-08-04
    • 2019-10-27
    相关资源
    最近更新 更多