react-lottie icon indicating copy to clipboard operation
react-lottie copied to clipboard

Uncaught TypeError: Cannot read property 'length' of undefined

Open XBLDev opened this issue 7 years ago • 13 comments

Hi first I just discovered this wrapper, great work!

I've been having this problem for a while now: one of my animations keeps giving me: Uncaught TypeError: Cannot read property 'length' of undefined

I tried using different bodymovin/lottie versions, none of them works, including this one.

My json file is in the attachment, can someone please have a look at it and tell me what's wrong with it? Thanks in advance for answer! Group1Image7BatteriesV3.zip

XBLDev avatar Feb 05 '18 09:02 XBLDev

I have the same problem, tried 3 different animations

uffou avatar May 03 '18 12:05 uffou

I also have this @chenqingspring

karahan avatar Oct 09 '18 10:10 karahan

This just started happening to us as well after upgrading node to 9.10 and react-scripts to 2.0.4.

UPDATE: I can confirm that downgrading react-scripts to 1.0.4 fixes this problem

luskin avatar Oct 12 '18 00:10 luskin

as a workaround I discovered you can do the following:

const defaultOptions = {
      loop: true,
      autoplay: true,
      animationData: require('./animation.json'),
      rendererSettings: {
        preserveAspectRatio: 'xMidYMid slice',
      },
    }

...


<Lottie options={defaultOptions} height={240} width={'75%'} />

instead of import * as animationData from './animation.json'

luskin avatar Oct 12 '18 01:10 luskin

Hey guys,

Having almost the same issue here, but I was able to solve it almost in the same way than @luskin did, but I think is better if you do the following:

import animationData from 'animation.json'

...

const defaultOptions = {
  ...
  animationData,
  ...
}

...

<Lottie options={defaultOptions} height={240} width={'75%'} />

Hope it helps!

eliasrodeloso avatar Nov 09 '18 15:11 eliasrodeloso

@eliasrodeloso thanks so much! You're a true hero!

mokutsu avatar Nov 21 '18 15:11 mokutsu

@eliasrodeloso I had this problem when I update webpack3 to webpack4. Thank you so much! Really helps me a lot!

BODhaha avatar Dec 13 '18 02:12 BODhaha

@chenqingspring You should update the doc accordingly 💯

melMass avatar Jan 05 '19 02:01 melMass

@eliasrodeloso thanks so much!

Jeewhan avatar Jan 31 '19 02:01 Jeewhan

I also had this problem and I solved it by installing a dependency of the oldest react-lottie library that is [email protected] and after installing it everything went back to normal

angelop11 avatar May 06 '19 04:05 angelop11

In my case also I'm getting this error:

bundle.1565612877825.js:1 Uncaught TypeError: Cannot read property 'length' of undefined
    at linear (bundle.1565612877825.js:1)

build is successfull but when i run it gives me above error. I need help with this because i'm not able to findout the exact issue here.

kirangadhiya avatar Aug 12 '19 12:08 kirangadhiya

I'm running into the same issue actually.

I'm curious, can we pass in a stringified object as the animationData? Does it have to read from a file with a .json extension?

In my test app I'm developing locally, I'm trying to dynamically render JSON strings but running into this same issue. Importing a .json file works as expected

lucasvocos avatar Aug 22 '19 16:08 lucasvocos

as a workaround I discovered you can do the following:

const defaultOptions = {
      loop: true,
      autoplay: true,
      animationData: require('./animation.json'),
      rendererSettings: {
        preserveAspectRatio: 'xMidYMid slice',
      },
    }

...


<Lottie options={defaultOptions} height={240} width={'75%'} />

instead of import * as animationData from './animation.json'

谢谢你!I`m from China!Thank you !Your method helped me!

DAHU123 avatar Nov 05 '19 03:11 DAHU123