relative module was not found: vue-lottie

2.5k Views Asked by At

After a fresh build with vue-cli (3.0.0-rc.5) the path to the lottie module can't be reached. Should I play with the configs?


  • ./lottie.vue in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/HelloWorld.vue?vue&type=script&lang=js&

<template>
<div id="app">
    <lottie :options="defaultOptions" :height="400" :width="400" v-on:animCreated="handleAnimation"/>
    <div>
        <p>Speed: x{{animationSpeed}}</p>
        <input type="range" value="1" min="0" max="3" step="0.5"
               v-on:change="onSpeedChange" v-model="animationSpeed">
    </div>
    <button v-on:click="stop">stop</button>
    <button v-on:click="pause">pause</button>
    <button v-on:click="play">play</button>
</div>

<script>
      import Lottie from './lottie.vue';
      import * as animationData from './assets/data.json';
      export default {
        name: 'app',
        components: {
          'lottie': Lottie
        },
        data() {
          return {
            defaultOptions: {animationData: animationData},
            animationSpeed: 1
          }
        },
        methods: {
          handleAnimation: function (anim) {
            this.anim = anim;
          },
          stop: function () {
            this.anim.stop();
          },
          play: function () {
            this.anim.play();
          },
          pause: function () {
            this.anim.pause();
          },
          onSpeedChange: function () {
            this.anim.setSpeed(this.animationSpeed);
          }
        }
      }
    </script>
2

There are 2 best solutions below

2
On BEST ANSWER

If you are using vue-lottie package then the import should be

import Lottie from 'vue-lottie';

This is because lottie package is located in the node_modules folder and you have to provide the right path or use direct package name import. On a side note, I believe the current version of Vue cli is v3.1.1 so you should definitely upgrade.

0
On

If it still doesn't work change animationData to animationData.default in defaultOptions

defaultOptions: { animationData: animationData.default }