0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Next.js + Rive でBad Header, Problem loading file; may be corrupted と出た時にチェックすること

Posted at

概要

こちらを見てNext.jsのアプリにrivをぶち込んで見ようとした時、

app/pages.tsx

では普通にレンダーできていたRiveComponentが、

app/chat-history/[id]/page.tsx

で呼ぼうとすると

Bad Header, Problem loading file; may be corrupted!

というエラーになってしまいました。

そもそものRiveComponentの呼び方

ミニマムなRiveComponentは

RivGirl.tsx
import { useRive } from "@rive-app/react-canvas";

export const RivGirl = () => {
    const { RiveComponent } = useRive({
        src: "girl.riv",
        autoplay: true,
    });

    return (
        <div style={{ width: "500px", height: "500px" }}>
            <RiveComponent />
        </div>
    )
}

としていました。
このとき、girl.riv
プロジェクトのルートにpublicフォルダを作り、
public/girl.riv とすること。

解決策

RivGirl.tsx
import { useRive } from "@rive-app/react-canvas";

export const RivGirl = () => {
    const { RiveComponent } = useRive({
        src: "/girl.riv",
        autoplay: true,
    });

    return (
        <div style={{ width: "500px", height: "500px" }}>
            <RiveComponent />
        </div>
    )
}

と、

src: "girl.riv"
から
src: "/girl.riv"

と / を入れる必要がありました。

この辺を見ていたときに/がないことに気づきました。

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?