rive-app / rive-react

React runtime for Rive

Home Page:https://rive-app.github.io/rive-react

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bad Header, Problem loading file; may be corrupted!

avanish-patel opened this issue · comments

I'm trying to create Spinner component using .riv file, when I add src as local file or via CDN when I render the component in consumer application it fails with following errors.

It renders correctly in component library as expected but error occurs when it's rendered in consuming react application.

Screen Shot 2022-12-12 at 11 49 25 AM

Following are the sources where it shows error in the browser.

Screen Shot 2022-12-12 at 11 49 43 AM

Screen Shot 2022-12-12 at 11 50 10 AM

commented

I'm getting the same issue when trying to load the file from the local "src" directory in "Create React App."

commented

So I found the problem and solution...

You need to place the .riv file into the public folder, not the src folder.

When the .riv file is in the public folder, you can "src" it directly.

Example:


const Logo = () => {
  const { RiveComponent } = useRive({
    src: "logo.riv",
    autoplay: true,
    onLoadError: () => console.log("ERROR LOADING RIVE"),
    onLoad: () => console.log("LOADED RIVE"),
  })
  return ( 
    <RiveComponent />
  );
};

export default Logo;```

In this example, logo.riv lives in public/logo.riv

@curtk Thanks for your response. Here I’m trying to create common component that uses .riv file and bundle that using rollup js. I couldn’t find any good documentation that walk met through how to bundle this .riv file for components that can be used in other projects.

I am deploying My react app in amplify Eventhough I moved to public in localhost its working but after deploying rive animation is giving this error :- Bad Header, Problem loading file; may be corrupted!